XSD Schema Error : the content model of complex type definition ' anonymous ' is ambiguous while multipal choice

StackOverflow https://stackoverflow.com/questions/23153278

  •  05-07-2023
  •  | 
  •  

Question

XSD Code: getting error- the content model of complex type definition ' anonymous ' is ambiguous

<xs:element name="data">
            <xs:complexType>
                <xs:choice>
                    <xs:choice minOccurs="0" maxOccurs="unbounded">
                        <xs:element name="A"/>
                        <xs:element name="B"/>
                        <xs:element name="C"/>
                        <xs:element name="D"/>
                        <xs:element name="EE"/>
                    </xs:choice>
                    <xs:choice minOccurs="0" maxOccurs="unbounded">
                        <xs:element name="A"/>
                        <xs:element name="B"/>
                        <xs:element name="C"/>
                        <xs:element name="D"/>
                        <xs:element name="FF"/>
                    </xs:choice>
                </xs:choice>
            </xs:complexType>
        </xs:element>
Was it helpful?

Solution

<xs:choice> selects one among many. You have nested choices. The parser complains that there is ambiguity because you have repeating elements declared in the neste choices, violating the Unique Particle Attribution constraint.

Example: If the first nested choice chooses A, and the second one also chooses A, you will have this illegal situation in your outer choice:

<xs:choice>
    <xs:element name="A"/>
    <xs:element name="A"/>
</xs:choice>

You can have one nested choice and accept multiple A elements, but not two identical element declarations.

Your code will work if you replace the outer choice for a sequence.

If you add more detail to your question this answer can be improved to show you a better alternative.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top