Question

I would like to create a XSD sequence where element can be unordered, but may have a bounded multiplicity. This question is similar but the multiplicity is not what I need.

<xs:complexType>
  <xs:sequence>
    <xs:choice>
      <xs:element name="a" minOccurs="0" />
      <xs:element name="b" maxOccurs="2" />
      <xs:element name="c" minOccurs="1" />
    </xs:choice>
  </xs:sequence>
</xs:complexType>

For example here I want some a, b and c in any order. But in the end I need a maximum of 2 b and a minimum of 1 c, and there can be 0 or a lot of a. How can I write this in XSD ?

Was it helpful?

Solution

This may not be achieved in XSD 1.0: you basically want an xsd:all compositor (scroll to the xsd:all example), where containing particles can have a maxOccurs > 1.

XSD 1.0 with Schematron would work with no issues.

XSD 1.1 relaxed this limitation; if you're interested in either of the alternatives, tag the question appropriately and I'll update the answer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top