How to allow/impose elements to occurs one time in any order. With Schema langauge (XSD)



The XML has a parent element "Parent", which have to contain 10 chils: child1 to child10 in any order, but exactly one time.


As an alternative, the parent element can optionally contain child11 to child20 instead of child1 to child10.



<parent><child1/><child4/> ... <child2/></parent> OK
<parent><child5/>...<child20/></parent> OK
<parent><child1/><child2/></parent> BAD, missing childs
<parent><child1/>...<child11/></parent> BAD: child11 shall never be with child1
<parent><child1/><child1/></parent> BAD: childs shall not be repeated


XSD tries:



<xs:complexType name="parent">
<xs:choice>
<xs:sequence>
<xs:element name="child1" type="xs:integer" minOccurs="1" maxOccurs="1"/>
<xs:element name="child2" type="xs:integer" minOccurs="1" maxOccurs="1"/>
...
</xs:sequence>
<xs:sequence>
<xs:element name="child11" type="xs:integer" minOccurs="1" maxOccurs="1"/>
<xs:element name="child12" type="xs:integer" minOccurs="1" maxOccurs="1"/>
...
</xs:sequence>
</xs:choice>
</xs:complexType>

No comments:

Post a Comment