I want to define a xml schema where the element Connectors have 0-* child elements. Either Sequence, Association or Message in any order and 0 to many times. I.e.
<Connectors>
<Sequence />
<Association />
<Message />
<Sequence />
<Sequence />
<Message />
<Message />
<Association />
</Connectors>
I tried to define the following schema but it seems like the order is fixed.
<xs:element name="Connectors">
<xs:complexType>
<xs:sequence>
<xs:element ref="Association" minOccurs="0" maxOccurs="unbounded" />
<xs:element ref="Message" minOccurs="0" maxOccurs="unbounded" />
<xs:element ref="Sequence" minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>
In the most general sense, XML element order does not matter, unless otherwise specified by the appropriate schema.
The all element specifies that the child elements can appear in any order and that each child element can occur zero or one time.
The minOccurs attribute specifies the minimum number of times that the element can occur. It can have a value of 0 or any positive integer. The maxOccurs attribute specifies the maximum number of times that the element can occur.
Definition and Usage The sequence element specifies that the child elements must appear in a sequence. Each child element can occur from 0 to any number of times.
I solved it by setting to choice and setting minOccurs and maxOccurs attributes.
<xs:element name="Connectors">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="Association" />
<xs:element ref="Message" />
<xs:element ref="Sequence" />
</xs:choice>
</xs:complexType>
</xs:element>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With