Matt Klaver
Matt Klaver

Reputation: 165

Allow sequence OR empty in XSD

Looking to figure out how to match either on a set sequence or no value. Example below of my sequence, but I'm stuck for how to get it to accept either the sequence as written, or the <body> tag existing with no value inside it.

<xs:element name="body">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="id"   type="xs:string"/>
            <xs:element name="name" type="xs:string"/>
            <xs:element name="type" type="xs:string"/>
            <xs:element name="user" type="xs:string"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>

I want the above to match on either a blank (as below) or a correctly filled tag.

<body></body>

Upvotes: 4

Views: 808

Answers (1)

kjhughes
kjhughes

Reputation: 111581

You can add a minOccurs="0" to xs:sequence to allow the entire sequence to be optional.

See also

Upvotes: 3

Related Questions