I would like to validate my XML using an XSD. The XML is supposed to contain complex elements with some (none to all) elements of a given set. I think the straight foward solution for the complex element is
<xs:sequence>
<xs:element name="foo" minOccurs="0" maxOccurs="1"/>
<xs:element name="bar" minOccurs="0" maxOccurs="1"/>
<xs:element name="bee" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
I want to get rid of the set order of elements, plus I want to get rid of the minOccurs="0"
in every line, so that
<foo>text</foo>
<bee>text</bee>
<bar>text</bar>
is also valid. My idea was to write
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element1>
<xs:element2>
...
</xs:choice>
</xs:sequence>
which should translate to "select one element of the list as many times as you want to."
But it does not allow me to put an appearance restriction (like maxOccurs=1
) on individual elements.
Is there a better way to validate an XML without forcing a given order of elements?