XML Schema choice element

Definition and Usage

The XML Schema choice element allows only one of the elements contained in the <choice> declaration to appear in the containing element.

Element Information

Occurrence Times Once in the group and complexType elements; unlimited for others.
Parent Element group, choice, sequence, complexType, restriction (simpleContent), extension (simpleContent), restriction (complexContent), extension (complexContent)
Content annotation, any, choice, element, group, sequence

Syntax

<choice
id=ID
maxOccurs=nonNegativeInteger|unbounded
minOccurs=nonNegativeInteger
any attributes
>
(annotation?,(element|group|choice|sequence|any)*)
</choice>

(The '?' symbol declares that the element can appear zero or once, and the '*' symbol declares that the element can appear zero or multiple times within the choice element.)

Attributes Description
id Optional. Specifies the unique ID of the element.
maxOccurs Optional. Specifies the maximum number of times the choice element can appear in the parent element. This value can be an integer greater than or equal to zero. If you do not want to set any limit on the maximum number, use the string "unbounded". The default value is 1.
minOccurs Optional. Specifies the minimum number of times the choice element can appear in the parent element. This value can be an integer greater than or equal to zero. To specify that this any group is optional, set this attribute to zero. The default value is 1.
any attributes Optional. Specifies any other attributes with non-schema namespace.

Example

<xs:element name="person">
  <xs:complexType>
    <xs:choice>
      <xs:element name="employee" type="employee"/>
      <xs:element name="member" type="member"/>
    </xs:choice>
  </xs:complexType>
</xs:element>

The above example defines that the "person" element must contain either an "employee" element or a "member" element.