XML technologies / XML Schema / XML Schema element reference / xs:choice (outside a group)
(Excerpt from “XML Schema” by Eric van der Vlist)
Compositor defining a group of mutually exclusive elements or compositors.
<xs:choice
id = xs:ID
maxOccurs = ( xs:nonNegativeInteger | "unbounded" ) : "1"
minOccurs = xs:nonNegativeInteger : "1"
{beliebige Attribute mit einem Nicht-Schema-Namensraum}
>
Content: (xs:annotation?, (xs:element | xs:group | xs:choice | xs:sequence | xs:any)
)*)
</xs:choice>May occur within: xs:choice (outside a group), xs:choice (within a group), xs:complexType (local definition), xs:complexType (global definition), xs:extension (complex content), xs:restriction (complex content), xs:sequence (within a group), xs:sequence (outside a group)
Description
xs:choice is a compositor defining mutually exclusive particles. In the instance document, only one particle may occur per occurrence of the xs:choice compositor. Its own occurrence count is controlled by attributes minOccurs and maxOccurs , while each particle’s occurrence count within one occurrence of xs:choice is controlled by that particle’s attributes minOccurs and maxOccurs.
Besides simple choices, “element ‘a’ or ‘b’ can be accepted here”, xs:choice is often used to bypass the restrictions of xs:all and define content models accepting an unlimited number of elements in arbitrary order; see the example.
If the particle used in an xs:choice compositor is an element, substitution groups can achieve a similar result.
Restrictions
The xs:choice compositor can violate the unique particle attribution and consistent declaration rules.
Example
<xs:choice>
<!-- Erlaubt entweder "name" oder die Sequenz "first-name", "middle-name" und "last-name". -->
<xs:element ref="name"/>
<xs:sequence>
<xs:element ref="first-name"/>
<xs:element ref="middle-name" minOccurs="0"/>
<xs:element ref="last-name"/>
</xs:sequence>
</xs:choice>Attributes
id
Element ID according to W3C XML Schema.
maxOccurs
Maximum occurrence count of the choice compositor.
minOccurs
Minimum occurrence count of the choice compositor.
Copyright © 2003 O'Reilly Verlag GmbH & Co. KG
You may print the online version for your private use.
Otherwise, this chapter from “XML Schema” is subject to the same conditions as the bound edition. The work, including all its parts, is protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
O’Reilly Verlag GmbH & Co. KG, Balthasarstraße 81, 50670 Köln, kommentar(at)oreilly.de