I am working on an XSD schema where the order of element is not supposed to be enforced. In other words, elements can appear in any order. Some elements are optionals and some are required. As far as I know, xs:sequence is suitable for this kind of situation but since xs:sequence enforces element order, I am only left with xs:choice which is very relaxed when it comes to enforcement. For example, consider an example:
<p>
<c1>can appear 0 to infinite # of times</c1>
<c2>must appear exactly once</c2>
<c1>here the optional element appears again</c1>
</p>
My XSD looks something like this:
<xs:element name="p">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="c1" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="c2" minOccurs="1" maxOccurs="1" />
</xs:choice>
</xs:complexType>
However, the above XSD does not enforce that the element "c2" appear exactly once. Element "c2" can be completely absent or can appear more than once and the XML is still considered valid.
Is there really any way I can allow:
- elements in any order and
- mix both optional & required elements inside xs:choice?