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?
The default values for
minOccurs
andmaxOccurs
are 1. Thus: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.
invalid
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.
is a valid combination which makes the element prohibited.
For more info see http://www.w3.org/TR/xmlschema-0/#OccurrenceConstraints
New, expanded answer to an old, commonly asked question...
Default Values
minOccurs
andmaxOccurs
default to1
.Common Cases Explained
means
A
is required and must appear exactly once.means
A
is optional and may appear at most once.means
A
is required and may repeat an unlimited number of times.means
A
is optional and may repeat an unlimited number of times.See Also
W3C XML Schema Part 0: Primer
W3C XML Schema Part 1: Structures Second Edition
Short answer:
As written in xsd:
If you provide an attribute with number, then the number is boundary. Otherwise attribute should appear exactly once.
example:
XML
XSD:
XSL:
Result: