Reputation: 157
I understand and use xs:choice
and xs:sequence
separately but I do not understand what xs:choice
inside xs:sequence
mean?
<xs:element name="sports-content">
<xs:complexType>
<xs:sequence>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="sports-metadata" />
<xs:element name="sports-event" />
<xs:element name="tournament" />
<xs:element name="schedule" />
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
Ok. This XML will be valid.
<sports-content>
<sports-metadata />
<tournament />
</sports-content>
Will this XML be valid or not?
<sports-content>
<sports-metadata />
<tournament />
<sports-metadata />
</sports-content>
Upvotes: 4
Views: 2848
Reputation: 111630
The xs:sequence
element in your XSD is superfluous; it can be removed without affecting validity of any XML document. An xs:sequence
around an xs:choice
would be useful, for example, if you wanted the choice to always be preceded or followed by one or more elements in sequence.
Yes, both of the XML documents in your question are valid against your XSD (and will continue to be if you remove the xs:sequence
wrapper around xs:choice
.
Upvotes: 3