Tamino XML Server Version 9.7
 —  Tamino XML Schema Reference Guide  —

xs:choice

Purpose

This element (the "choice" particle) expresses a choice in complex type definitions of elements.

It allows one of the particles contained in its scope to be present in instances of the containing element. The number of times that one particle may be chosen from the list is bounded by the values of the minOccurs and maxOccurs attributes.

Parent element xs:choice, xs:complexType, xs:extension, xs:group, xs:sequence
Child elements xs:any, xs:choice, xs:element, xs:group, xs:sequence
Attributes minOccurs, maxOccurs
Attributes
Name Type Description
minOccurs xs:nonNegativeInteger Together with the maxOccurs attribute described below, this attribute expresses multiplicity in TSD (and XML Schema) in choice elements within element definitions. The value of the minOccurs attribute in an xs:choice declaration determines the minimum number of occurrences of xs:choice. The value of the minOccurs attribute must be a non-negative integer. The default value of minOccurs is 1.
maxOccurs xs:nonNegativeInteger or "unbounded" Together with the minOccurs attribute described above, this attribute expresses multiplicity in TSD (and XML Schema) in choice elements within element definitions. The value of a maxOccurs attribute in an xs:choice declaration determines the maximum number of occurrences of xs:choice. The value of the maxOccurs attribute must be a non-negative integer or "unbounded". The default value of maxOccurs is 1.

Example 1

The example below defines an element partner which must contain either a customer element or a supplier element or an employee element.

<xs:element name="partner">
  <xs:complexType>
    <xs:choice>
      <xs:element name="customer" type="t_customer"/>
      <xs:element name="supplier" type="t_supplier"/>
      <xs:element name="employee" type="t_employee"/>
    </xs:choice>
  </xs:complexType>
</xs:element>

Example 2

The example below defines an element named partner which may contain either a customer element or a supplier element or an employee element.

<xs:element name="partner">
  <xs:complexType>
    <xs:choice minOccurs="0">
      <xs:element name="customer" type="t_customer"/>
      <xs:element name="supplier" type="t_supplier"/>
      <xs:element name="employee" type="t_employee"/>
    </xs:choice>
  </xs:complexType>
</xs:element>

Top of page