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:

https://www.w3schools.com/xml/schema_complex_any.asp

Leave a Comment