tags:

views:

78

answers:

1

I am trying to make a simple XSD choice construct allowing either one or both of two referenced elements, but not none. The construct is similar to below but I keep getting an ambiguity error. What am I missing?

<xs:schema xmlns:xs="...">
  <xs:element name="Number" type="xs:integer"/>
  <xs:element name="Text" type="xs:string"/>
  <xs:element name="RootStructure">
    <xs:complexType>
      <xs:sequence>
        <xs:choice>
          <xs:sequence>
            <xs:element ref="Number"/>
            <xs:element ref="Text"/>
          </xs:sequence>
          <xs:element ref="Number"/>
          <xs:element ref="Text"/>
        </xs:choice>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>
+2  A: 

The usual way to do it is this:

<xs:schema xmlns:xs="...">
  <xs:element name="Number" type="xs:integer"/>
  <xs:element name="Text" type="xs:string"/>
  <xs:element name="RootStructure">
    <xs:complexType>
      <xs:sequence>
        <xs:choice>
          <xs:sequence>
            <xs:element ref="Number"/>
            <xs:element ref="Text" minOccurs="0"/>
          </xs:sequence>
          <xs:element ref="Text"/>
        </xs:choice>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>
xcut