XML validation with XSD: how to avoid caring about the sequence of the elements?
<xsd:complexType name="questions"> <xsd:all> <xsd:element name="location" type="location"/> <xsd:element name="multipleChoiceInput" type="multipleChoiceInput"/> <xsd:element name="textInput" type="textInput"/> <xsd:element name="pictureInput" type="pictureInput"/> </xsd:all></xsd:complexType>
NOTE: I have changed "sequence" to "all"
Sequence forces order (as defined). if order doesn't matter then all is used.
If there are chances of element occurence more than once then xsd:any can be used.
<xsd:complexType name="questions"> <xsd:sequence> <xsd:any minOccurs="0"/> </xsd:sequence></xsd:complexType>
You can find details of xsd:any at following link:
I'm a little late to this discussion, but I had the same problem and found the solution:
<xsd:complexType name="questions"> <xsd:choice maxOccurs="unbounded"> <xsd:element name="location" type="location"/> <xsd:element name="multipleChoiceInput" type="multipleChoiceInput"/> <xsd:element name="textInput" type="textInput"/> <xsd:element name="pictureInput" type="pictureInput"/> </xsd:choice></xsd:complexType>
The key is to combine xs:choice with maxOccurs="unbounded". If you just use xs:all, you are allowed one of each, period.
edited to add:While xs:any will work, it won't limit your choices to the four elements itemized. It will allow anything, which pretty much defeats the purpose of a schema.
Also very late to the party here, but would using <xsd:all>
in conjunction with minOccurs
and maxOccurs
not work?:
<xsd:complexType name="questions"> <xsd:all> <xsd:element name="location" type="location" minOccurs="0" maxOccurs="1"/> <xsd:element name="multipleChoiceInput" type="multipleChoiceInput" minOccurs="0" maxOccurs="1"/> <xsd:element name="textInput" type="textInput" minOccurs="0" maxOccurs="1"/> <xsd:element name="pictureInput" type="pictureInput" minOccurs="0" maxOccurs="1"/> </xsd:all></xsd:complexType>