tags:

views:

17

answers:

2

I want to define a schema that allows child elements to occur in any order, similar to <choice minOccurs="0" maxOccurs="unbounded"> but will allow only one of each element, similar to <sequence minOccurs="1" maxOccurs="1">

can this be done?

for example

<Root>
 <ele1>
 <ele3>
 <ele2>
</Root>    <!--Valid-->

And as below:

<Root>
 <ele1>
 <ele1>
 <ele3> 
</Root> <!--Invalid-->
A: 

You can add maxOccurs="1" to the element.

Mitchel Sellers
i tried this several ways in several places, but it doesn't seem to be enforced. Maybe i did it wrong?
Beta033
A: 

Use xs:all rather than xs:sequence, so you'd write:

<xs:element name="Root">
    <xs:complexType>
            <xs:all>
                <xs:element name="element1"/>
                <xs:element name="element2"/>
                <xs:element name="element3"/>
            </xs:all>
    </xs:complexType>
</xs:element>
Aled G
AHA! thanks. i discovered this as well in my testing. Thanks!
Beta033