XSD Indicators
With indicators, we can control how elements are used in a document.
Indicators
There are seven indicators:
Order indicators:
- All
- Choice
- Sequence
Occurrence indicators:
- maxOccurs
- minOccurs
Group indicators:
- Group name
- attributeGroup name
Order Indicators
Order indicators are used to define the order of elements.
The All Indicator
Note: When using
The Choice Indicator
The Sequence Indicator
Occurrence Indicators
Occurrence indicators are used to define how often an element can occur.
**Note:** For all "Order" and "Group" indicators (any, all, choice, sequence, group name, and group reference), the default value of maxOccurs and minOccurs is 1.
The maxOccurs Indicator
The example above shows that the child element "child_name" can occur a minimum of one time (where the default value of minOccurs is 1) and a maximum of 10 times in the "person" element.
The minOccurs Indicator
maxOccurs="10" minOccurs="0"/>
The example above shows that the child element "child_name" can occur a minimum of 0 times and a maximum of 10 times in the "person" element.
**Tip:** To allow an element to occur an unlimited number of times, use the declaration maxOccurs="unbounded":
A real example:
An XML file named "Myfamily.xml":
xsi:noNamespaceSchemaLocation="family.xsd"> The XML file above has a root element named "persons". Inside this root element, we have defined three "person" elements. Each "person" element must contain one "full_name" element, and it can contain up to 5 "child_name" elements. This is the schema file "family.xsd": elementFormDefault="qualified"> minOccurs="0" maxOccurs="5"/> Group indicators are used to define related sets of elements. Element groups are defined with the group declaration: ... You must define an all, choice, or sequence element inside the group declaration. The following example defines a group named "persongroup", which defines a set of elements that must appear in an exact order: After you have defined the group, you can reference it in another definition: Attribute groups are defined with the attributeGroup declaration: ... The following example defines an attribute group named "personattrgroup": After you have defined the attribute group, you can reference it in another definition, like this:
Group Indicators
Element Groups
Attribute Groups