XSD “one or both” choice construct leads to ambiguous content model

后端 未结 2 1533
旧时难觅i
旧时难觅i 2021-02-07 05:23

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 a

相关标签:
2条回答
  • 2021-02-07 05:54

    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>
    
    0 讨论(0)
  • 2021-02-07 06:14

    Some additional hint, if you have multiple elements linked and you want one bundle of elements or the other bundle, or both, you can do it like this:

    <xsd:complexType name="ComplexTypeName">
        <xsd:choice>
            <xsd:sequence>
                <xsd:element name="theElement" />
                <xsd:element name="theElementIsFlagged" />
                <xsd:choice>
                    <xsd:sequence>
    <!-- note the empty sequence block -->
                    </xsd:sequence>
                    <xsd:sequence>
                        <xsd:element name="theOtherElement" />
                        <xsd:element name="theOtherElementIsFlagged" />
                    </xsd:sequence>
                </xsd:choice>
            </xsd:sequence>
            <xsd:sequence>
                <xsd:element name="theOtherElement" />
                <xsd:element name="theOtherElementIsFlagged" />
            </xsd:sequence>
        </xsd:choice>
    </xsd:complexType>
    

    Just in case some of you bump into the same issue!!

    0 讨论(0)
提交回复
热议问题