Indicators control the way how elements are to be organized in an XML document.
Indicators
There are seven types of indicators that fall into three broad categories.
Order Indicators
- All: Child elements can occur in any order.
- Choice: Only one of the child element can occur.
- Sequence: Child element can occur only in specified order.
Occurrence Indicators
- maxOccurs: Child element can occur only maxOccurs number of times.
- minOccurs: Child element must occur minOccurs number of times.
Group Indicators
- Group: Defines related set of elements.
- attributeGroup: Defines related set of attributes.
Order Indicators
Order indicators are used to define the order of the elements.
All Indicator
The <xs:all> indicator specifies that the child elements can appear in any order, and that each child element must occur only once:
<xs:element name="person">
<xs:complexType>
<xs:all>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
</xs:all>
</xs:complexType>
</xs:element>Choice Indicator
The <xs:choice> indicator specifies that either one child element or another can occur:
<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>Sequence Indicator
The <xs:sequence> indicator specifies that the child elements must appear in a specific order:
<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>Occurrence Indicators
Occurrence indicators are used to define how often an element can occur.
maxOccurs Indicator
The maxOccurs indicator specifies the maximum number of times an element can occur:
<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element name="full_name" type="xs:string"/>
<xs:element name="child_name" type="xs:string" maxOccurs="10"/>
</xs:sequence>
</xs:complexType>
</xs:element>minOccurs Indicator
The minOccurs indicator specifies the minimum number of times an element can occur:
<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element name="full_name" type="xs:string"/>
<xs:element name="child_name" type="xs:string" minOccurs="0" maxOccurs="10"/>
</xs:sequence>
</xs:complexType>
</xs:element>Group Indicators
Group indicators are used to define related sets of elements.
Element Groups
Element groups are defined with the group declaration in this way:
<xs:group name="groupname">
...
</xs:group>For example:
<xs:group name="persongroup">
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
<xs:element name="birthday" type="xs:date"/>
</xs:sequence>
</xs:group>
<xs:element name="person" type="personinfo"/>
<xs:complexType name="personinfo">
<xs:sequence>
<xs:group ref="persongroup"/>
<xs:element name="country" type="xs:string"/>
</xs:sequence>
</xs:complexType>Attribute Groups
Attribute groups are defined with the attributeGroup declaration in this way:
<xs:attributeGroup name="groupname">
...
</xs:attributeGroup>For example:
<xs:attributeGroup name="personattrgroup">
<xs:attribute name="firstname" type="xs:string"/>
<xs:attribute name="lastname" type="xs:string"/>
<xs:attribute name="birthday" type="xs:date"/>
</xs:attributeGroup>
<xs:element name="person">
<xs:complexType>
<xs:attributeGroup ref="personattrgroup"/>
</xs:complexType>
</xs:element>