0

Im trying to write a schema for an element that can be in 1 of 2 formats. here is the XML example

XML

<root>
  <ElementName> <!--if value starts with "A"-->
     <SubElementName1\>
     <SubElementName2\>
     <SubElementName3\>
  <ElementName\>
<!--Only one of these structures exist per document-->
  <ElementName><!--value starts with "B"-->
     <SubElementName4\>
     <SubElementName5\>
     <SubElementName6\>
     <SubElementName7\>
     <SubElementName8\>
     <SubElementName9\>
  <ElementName\>

XSD

        <xsd:choice>
            <xsd:element name="ElementName">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element name="SubElementName1"/>
                        <xsd:element name="SubElementName2"/>
                        <xsd:element name="SubElementName3"/>/>
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>
        </xsd:choice>
            <xsd:choice>
            <xsd:element name="ElementName">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element name="SubElementName4"/>
                        <xsd:element name="SubElementName5"/>
                        <xsd:element name="SubElementName6"/>
                        <xsd:element name="SubElementName7"/>
                        <xsd:element name="SubElementName8"/>
                        <xsd:element name="SubElementName9"/>
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>
        </xsd:choice>

Ive tried using in various ways but cant seem to get it to validate. The error message I get is this

cos-element-consistent: Error for type '#AnonType_Root'. Multiple elements with name 'ElementName', with different types, appear in the model group.

  • Your example is not clear. The tag 'ElementName' does not have a value at all in either of the choice branches. Please edit your question and add the missing values to the example. – kimbert Mar 24 '20 at 18:44
  • Im document, element name will not have a value, just a list of child elements. I guess an example might be that ADDRESS can have child elements NUMBER, STREET, CITY, ZIP.....OR it can have child elements IP_ADDRESS, MAC_ADDRESS. But both structures cant exist at once. – TheUltimateHack Mar 28 '20 at 19:09
  • But the comment in your XML says 'If the _value_ starts with A' Please edit your example XML. I recommend using the example in your comment about, instead of the (rather abstract) example that you are currently using. – kimbert Mar 30 '20 at 08:58
  • Gotcha. I meant subelement1 starts with A but its the same either or. Im basically asking if there is a way to use choice such that there are e instances of "ElementName" in the same schema doc – TheUltimateHack Mar 31 '20 at 15:09
  • Sorry, but I still have no idea what you mean. Why don't you edit your question and show me? – kimbert Mar 31 '20 at 16:10

0 Answers0