XML Schema choiceElement
Complete XML Schema Reference Manual
Definition and Usage
The XML Schema choice element only allows
Element Information
- Parent elements: group, choice, sequence, complexType, restriction (both simpleContent and complexContent), extension (both simpleContent and complexContent)
Syntax
<choice
id=ID
maxOccurs=nonNegativeInteger|unbounded
minOccurs=nonNegativeInteger
any attributes
>
(annotation?,(element|group|choice|sequence|any)*)
</choice>
id=ID
maxOccurs=nonNegativeInteger|unbounded
minOccurs=nonNegativeInteger
any attributes
>
(annotation?,(element|group|choice|sequence|any)*)
</choice>
(The ? symbol declares that an element in the choice element may appear zero or one time; the * symbol declares that an element may appear zero or more times.)
| Attributes | Description |
|---|---|
| id | Optional. Specifies a unique ID for the element. |
| maxOccurs | Optional. Specifies the maximum number of times the choice element can appear in the parent element. The value can be an integer greater than or equal to zero. To set no 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. The 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 a non-schema namespace. |
Example 1
<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>
<xs:complexType>
<xs:choice>
<xs:element name="employee" type="employee"/>
<xs:element name="member" type="member"/>
</xs:choice>
</xs:complexType>
</xs:element>
The example above defines that the "person" element must contain either an "employee" element or a "member" element.
Complete XML Schema Reference Manual Other Extensions