XSD schema accepting choice of 3 elements (strictly one time) and other two optional elements which may follow in any order

Viewed 349

I'm writing a schema that I would like to define the following structures (assume we have types A, B, C, D, E). The schema should accept one of [A, B or C] which must appear and appear only 1 time + one of [D or E] which might appear either single or both or none of both but not more than one time each. Both ABC and DE classes' elements should be insensitive to the order they follow. In other words the following examples are accepted:

<root>
    <el_A/>
</root>

<root>
    <el_B/>
    <el_E/>
    <el_D/>
</root>

<root>
    <el_C/>
    <el_D/>
</root>

And here are few examples of what the schema should not accept:

<root>
    <el_A/>
    <el_B/>
    <el_E/>
    <el_D/>
</root> 

<root>
    <el_C/>
    <el_D/>
    <el_D/>
</root> 

My type defined for root looks like this:

<xs:complexType>
    <xs:sequence>
        <xs:choice minOccurs="1" maxOccurs="1">
            <xs:element name="el_A" type="tns:A"/>
            <xs:element name="el_B" type="tns:B"/>
            <xs:element name="el_C" type="tns:C"/>
        </xs:choise>
        <xs:choice minOccurs="0">
            <xs:sequence>
                <xs:element name="el_D" type="tns:D" minOccurs="1" maxOccurs="1"/>
                <xs:element name="el_E" type="tns:E" minOccurs="1" maxOccurs="1"/>
            </xs:sequence>
            <xs:sequence>
                <xs:element name="el_E" type="tns:E" minOccurs="1" maxOccurs="1"/>
                <xs:element name="el_D" type="tns:D" minOccurs="1" maxOccurs="1"/>
            </xs:sequence>
            <xs:element name="el_E" type="tns:E"/>
            <xs:element name="el_D" type="tns:D"/>
        </xs:choise>
    </xs:sequence>
</xs:complexType>   

However when validating the documen against this schema the processor reports "cos-nonambig" error for el_D. I cannot understand why this schema allows ambigous interpretation since this describe a choise among three elements: either both exist in DE order, or both exist in ED order or only E exist or only D exist.

1 Answers
Related