【问题标题】:scalaxb and multiple groupsscalaxb 和多个组
【发布时间】:2014-02-08 09:24:04
【问题描述】:

在 MusicXML (http://www.musicxml.com/for-developers/) 上使用 scalaxb 1.1.2 (http://scalaxb.org),我得到了以下 sn-p:

<xs:complexType name="part-list">
    <xs:sequence>
        <xs:group ref="part-group" minOccurs="0" maxOccurs="unbounded"/>
        <xs:group ref="score-part"/>
        <xs:choice minOccurs="0" maxOccurs="unbounded">
            <xs:group ref="part-group"/>
            <xs:group ref="score-part"/>
        </xs:choice>
    </xs:sequence>
</xs:complexType>

这会导致非法继承:

  trait DefaultGeneratedPartu45listFormat extends scalaxb.ElemNameParser[generated.Partu45list] 
    with GeneratedPartu45groupGroupFormat 
    with GeneratedScoreu45partGroupFormat 
    with GeneratedPartu45groupGroupFormat {

    ...    
  }

如你所见,GeneratedPartu45groupGroupFormat 的双重继承会使编译不愉快。

所以我有两个问题:

  1. 有没有办法通过将 XSD 更改为 scalaxb 理解的等价物?

  2. 有没有办法配置 scalaxb 来处理这个问题 感激不尽?

【问题讨论】:

  • Scalaxb 绝不应该产生不可编译的代码。我看到您通过在 GitHub 上为该项目打开一个问题已经做了正确的事情。 Eugene 提供了一个建议来纠正您的问题。这个问题与您在这里提到的问题不同吗?同时尝试使用 scalaxb 用户组 (groups.google.com/forum/#!forum/scalaxb)。尤金通常与社区中的其他人一样反应迅速。在那里解决问题的机会更高。
  • 我还没有为这个问题打开一个问题,因为我认为它是一个复杂的问题(需要修复一个小例子)。我目前有兴趣让 XML 解析器工作,所以我对一些允许我这样做的 XSD hack 感兴趣;)。一旦我来提供一小段触发这个错误的 XML,我肯定会打开一个问题。

标签: scala xsd scalaxb


【解决方案1】:

我目前有兴趣让 XML 解析器工作,所以我对一些允许我这样做的 XSD hack 感兴趣;)。

你可以做一个简单的替换来解析编译的语法:

<xs:complexType name="part-list">
  <xs:choice maxOccurs="unbounded">
    <xs:group ref="part-group" />
    <xs:group ref="score-part" />
  </xs:choice>
</xs:complexType>

一旦我提供了一小段触发这个错误的 XML,我肯定会打开一个问题。

这是一个可以重现该问题的快速示例 XSD:

<xs:schema targetNamespace="http://www.example.com/music"
        elementFormDefault="qualified"
        xmlns="http://www.example.com/music"
        xmlns:xs="http://www.w3.org/2001/XMLSchema"
        xmlns:music="http://www.example.com/music">
  <xs:complexType name="part-list">
      <xs:sequence>
          <xs:group ref="part-group" minOccurs="0" maxOccurs="unbounded"/>
          <xs:group ref="score-part"/>
          <xs:choice minOccurs="0" maxOccurs="unbounded">
              <xs:group ref="part-group"/>
              <xs:group ref="score-part"/>
          </xs:choice>
      </xs:sequence>
  </xs:complexType>

  <xs:group name="part-group">
    <xs:sequence>
      <xs:element name="part" type="xs:string"/>
    </xs:sequence>
  </xs:group>

  <xs:group name="score-part">
    <xs:sequence>
      <xs:element name="score" type="xs:string"/>
    </xs:sequence>
  </xs:group>
</xs:schema>

请在 Github 上提交问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多