We can control HOW elements are to be used in documents with indicators.
There are seven indicators:
Order indicators:
Occurrence indicators:
Group indicators:
Order indicators are used to define the order of the elements.
The <all> indicator specifies that the child elements can appear in any order, and that each child element must occur only once:
Note: When using the <all> indicator you can set the <minOccurs> indicator to 0 or 1 and the <maxOccurs> indicator can only be set to 1 (the <minOccurs> and <maxOccurs> are described later).
The <choice> indicator specifies that either one child element or another can occur:
The <sequence> indicator specifies that the child elements must appear in a specific order:
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 for maxOccurs and minOccurs is 1.
The <maxOccurs> indicator specifies the maximum number of times an element can occur:
The example above indicates that the "friend_name" element can occur a minimum of one time (the default value for minOccurs is 1) and a maximum of ten times in the "person" element.
The <minOccurs> indicator specifies the minimum number of times an element can occur:
The example above indicates that the "friend_name" element can occur a minimum of zero times and a maximum of ten times in the "person" element.
Hint: To allow an element to appear an unlimited number of times, use the maxOccurs="unbounded" statement:
A working example:
An XML file called "Myfamily.xml":
The XML file above contains a root element named "persons". Inside this root element we have defined three "person" elements. Each "person" element must contain a "full_name" element and it can contain up to five "friend_name" elements.
Here is the schema file "family.xsd":
Group indicators are used to define related sets of elements.
Element groups are defined with the group declaration, like this:
You must define an all, choice, or sequence element inside the group declaration. The Below example defines a group named "persongroup", that defines a group of elements that must occur in an exact sequence:
After you have defined a group, you can reference it in another definition, like this:
Attribute groups are defined with the attributeGroup declaration, like this:
The Below example defines an attribute group named "personattrgroup":
After you have defined an attribute group, you can reference it in another definition, like this:
Your Query was successfully sent!