What is the difference between:
<choice maxOccurs="unbounded">
<element ref="test:A" maxOccurs="1"/>
</choice>
And:
<choice maxOccurs="1">
<element ref="test:A" maxOccurs="unbounded"/>
</choice>
For any practical purpose?
What is the difference between:
<choice maxOccurs="unbounded">
<element ref="test:A" maxOccurs="1"/>
</choice>
And:
<choice maxOccurs="1">
<element ref="test:A" maxOccurs="unbounded"/>
</choice>
For any practical purpose?
There is no difference in that particular combination. Choosing a single alternative an unbounded number of times is the same as choosing once to allow an unbounded number of a single alternative.
xsd:choice
CardinalityWhen @minOccurs
or @maxOccurs
appear on xs:choice
, the minimum or maximum number of times the number of choices among the alternatives is constrained.
Then, for each such choice, the cardinality of the chosen child alternative comes into play.
The following are some examples expressed in regular expression notation. Examples of valid sequences for the given combination are also provided.
<choice minOccurs="1" maxOccurs="1">
<element name="A" minOccurs="1" maxOccurs="1"/>
<element name="B" minOccurs="1" maxOccurs="1"/>
</choice>
Regex: [AB]
Valid sequences include:
<choice minOccurs="0" maxOccurs="1">
<element name="A" minOccurs="1" maxOccurs="1"/>
<element name="B" minOccurs="1" maxOccurs="1"/>
</choice>
Regex: [AB]?
Valid sequences include:
<choice minOccurs="1" maxOccurs="unbounded">
<element name="A" minOccurs="1" maxOccurs="1"/>
<element name="B" minOccurs="1" maxOccurs="1"/>
</choice>
Regex: [AB]+
Valid sequences include:
<choice minOccurs="1" maxOccurs="1">
<element name="A" minOccurs="1" maxOccurs="unbounded"/>
<element name="B" minOccurs="1" maxOccurs="unbounded"/>
</choice>
Regex: A+|B+
Valid sequences include:
<choice minOccurs="1" maxOccurs="1">
<element name="A" minOccurs="0" maxOccurs="1"/>
<element name="B" minOccurs="0" maxOccurs="unbounded"/>
</choice>
Regex: A?|B*
Valid sequences include:
<choice minOccurs="0" maxOccurs="unbounded">
<element name="A" minOccurs="1" maxOccurs="1"/>
<element name="B" minOccurs="1" maxOccurs="1"/>
</choice>
Or
<choice minOccurs="0" maxOccurs="unbounded">
<element name="A" minOccurs="0" maxOccurs="unbounded"/>
<element name="B" minOccurs="0" maxOccurs="unbounded"/>
</choice>
Or
<choice minOccurs="0" maxOccurs="unbounded">
<element name="A" minOccurs="1" maxOccurs="1"/>
<element name="B" minOccurs="1" maxOccurs="unbounded"/>
</choice>
Etc
Regex: [AB]*
Valid sequences include:
The default value for both @minOccurs
and @maxOccurs
is 1.
Nothing, in that particular case, but the difference shows up when you add alternatives to the choice:
<choice maxOccurs="unbounded">
<element ref="test:A" maxOccurs="1"/>
<element ref="test:B" maxOccurs="1"/>
</choice>
would allow any number of A and B elements in any order, whereas
<choice maxOccurs="1">
<element ref="test:A" maxOccurs="unbounded"/>
<element ref="test:B" maxOccurs="unbounded"/>
</choice>
allows any number of As or any number of Bs but not a mixture of the two.
<complexType name="cxT1"> <choice maxOccurs="unbounded"> <element ref="test:A" maxOccurs="1"/> </choice> </complexType> <complexType name="cxT2"> <complexContent> <restriction base="test:cxT1"> <choice maxOccurs="1"> <element ref="test:A" maxOccurs="2"/> </choice> </restriction> </complexContent> </complexType>
–
Sucker © 2022 - 2024 — McMap. All rights reserved.