XML Schema, One of each child element?
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 o开发者_JS百科nly 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-->
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>
You can add maxOccurs="1"
to the element.
精彩评论