<xsd:choice> Element 

Allows one and only one of the elements contained in the selected group to be present within the containing element.

<choice
  id = ID 
  maxOccurs= (nonNegativeInteger | unbounded) : 1
  minOccurs= nonNegativeInteger : 1 
  {any attributes with non-schema Namespace}...>
Content: (annotation?, (element | group | choice | sequence | any)*)
</choice>

Attributes

  • id
    The ID of this element. The id value must be of type ID and be unique within the document containing this element.

    Optional.

  • maxOccurs
    The maximum number of times the choice can occur. The value can be an integer greater than or equal to zero. To set no limit on the maximum number, use the string "unbounded". Default value is 1.

    Optional.

  • minOccurs
    The minimum number of times the choice can occur. The value can be an integer greater than or equal to zero. To specify that this choice group is optional, set this attribute to zero. Default value is 1.

    Optional.

Element Information

Number of occurrences

One within group and complexType elements; otherwise, unlimited.

Parent elements

group, choice, sequence, complexType, restriction (simpleContent), extension (simpleContent), restriction (complexContent), extension (complexContent)

Contents

annotation, any, choice, element, group, sequence

Example

The following complex type defines an element with one attribute and one and only one element from a choice of four specified elements.

<xs:complexType name="chadState">
 <xs:choice minOccurs="1" maxOccurs="1">
  <xs:element ref="selected"/>
  <xs:element ref="unselected"/>
  <xs:element ref="dimpled"/>
  <xs:element ref="perforated"/>
 </xs:choice>
 <xs:attribute name="candidate" type="candidateType"/>
</xs:complexType>

Other Resources

For more information see the W3C XML Schema Part 1: Structures Recommendation at www.w3.org/TR/2001/REC-xmlschema-1-20010502\#element-all.

See Also

Reference

XML Schemas (XSD) Reference
XML Schema Elements