1

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

<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 来感激地处理这个问题?

4

1 回答 1

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 上提交问题。

于 2014-02-08T17:14:07.573 回答