XML Schema minOccurs / maxOccurs default values

Chris picture Chris · Jan 27, 2011 · Viewed 239.1k times · Source

I'm wondering how the XML Schema specification handles these cases:

<xsd:element minOccurs="1" name="asdf"/>

No maxOccurs given -> Is this the cardinality [1..1]?

<xsd:element minOccurs="5" maxOccurs="2" name="asdf"/>

I suppose this is simply invalid?

<xsd:element maxOccurs="2" name="asdf"/>

Is this the cardinality [0..2] or [1..2]?

Is there an "official" definition on how the XML Schema spec handles these cases?

Answer

jasso picture jasso · Jan 27, 2011

The default values for minOccurs and maxOccurs are 1. Thus:

<xsd:element minOccurs="1" name="asdf"/>

cardinality is [1-1] Note: if you specify only minOccurs attribute, it can't be greater than 1, because the default value for maxOccurs is 1.

<xsd:element minOccurs="5" maxOccurs="2" name="asdf"/>

invalid

<xsd:element maxOccurs="2" name="asdf"/>

cardinality is [1-2] Note: if you specify only maxOccurs attribute, it can't be smaller than 1, because the default value for minOccurs is 1.

<xsd:element minOccurs="0" maxOccurs="0"/>

is a valid combination which makes the element prohibited.

For more info see http://www.w3.org/TR/xmlschema-0/#OccurrenceConstraints