Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can XSD choice be empty?

Tags:

xml

xsd

I've read the XSD specification but I'm still confused. Is an empty choice valid in XSD? I mean, with a simple choice with no attributes declared, is mandatory to have either element "a" or element "b", or can it be empty?

<xs:complexType name="ChoiceType">
    <xs:choice>
        <xs:element name="a" type="type_a"/>
        <xs:element name="b" type="type_b"/>
    </xs:choice>
</xs:complexType>
like image 974
JavierTP Avatar asked Jul 24 '26 18:07

JavierTP


1 Answers

Yes, the element governed by an xsd:choice can be empty, if minOccurs="0" is used:

  • minOccurs="0" can be on the xsd:choice itself.
  • minOccurs="0" can be on all of the children.

Related answer: An xsd:choice itself can be empty and would indicate that the element being defined must be empty.

Finally, note that in your example, no, one of a or b must be present because the default for minOccurs is 1.

like image 166
kjhughes Avatar answered Jul 27 '26 14:07

kjhughes



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!