I am trying to create an XSD, and trying to write the definition with the following requirement:
- Allow child element specified to appear any number of times (0 to unbounded)
- Allow child elements to be in any order
I looked around and found various solutions like this:
<xs:element name="foo">
<xsl:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="child1" type="xs:int"/>
<xs:element name="child2" type="xs:string"/>
</xs:choice>
</xs:complexType>
</xs:element>
But from what I understand xs:choice still only allows single element selection. Hence setting the MaxOccurs to unbounded like this should only mean that "any one" of the child elements can appear multiple times. Is this accurate?
If above solution is incorrect, how can I achieve what I stated above in my requirement?
EDIT: What if the requirement is as follows?
- Element child1 child2 can appear any number of times (0 to unbounded)
- Elements to be in any order
- Elements child3 and child4 should appear exactly once.
For example, this xml is valid:
<foo>
<child1> value </child1>
<child1> value </child1>
<child3> value </child3>
<child2> value </child2>
<child4> value </child4>
<child1> value </child1>
</foo>
but this is not (missing child3)
<foo>
<child1> value </child1>
<child1> value </child1>
<child2> value </child2>
<child4> value </child4>
<child1> value </child1>
</foo>