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.

   

 

 

 

back to top