Designing Your Own XML Schema: Indicators
(Page 1 of 6 )
This is the fourth (and last) in this series of articles, which guides you in designing XML Schemas right from the basics without any hurdles. This part explains what indicators are and how to use them.
If you are new to XML Schema, I strongly suggest you to go through my first article in the same series, which you can find right here.
The All indicator in XML Schema
Indicators? What are they?
Indicators are specially used to control the occurrences of elements in different orders. Sometimes, we may want certain elements to occur only once, or certain elements may not be in a particular order, or certain elements may not be necessary at all (optional) and so on. We can handle these kinds of issues by using indicators.
One of them is the “All” indicator. It is specially used to inform that the child elements of a parent element (of the complex type) can occur in any order and only once. Let us consider the following schema:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault=
"unqualified">
<xs:element name="Employees">
<xs:annotation>
<xs:documentation>Contains All Employee
information</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="Employee" >
<xs:complexType>
<xs:all>
<xs:element name="ID"
type="xs:string" />
<xs:element name="Name"
type="xs:string" />
</xs:all>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:key name="PK_Employee_ID">
<xs:selector xpath=".//Employee" />
<xs:field xpath="ID" />
</xs:key>
</xs:element>
</xs:schema>
The most important fragment to concentrate on is the following:
<xs:element name="Employee" >
<xs:complexType>
<xs:all>
<xs:element name="ID" type="xs:string" />
<xs:element name="Name" type="xs:string" />
</xs:all>
</xs:complexType>
</xs:element>
The above specifies that the “Employee” element mainly contain “ID” and “Name” elements, which can occur in any order and must exist.
Next: The Choice indicator in XML Schema >>
More XML Articles
More By Jagadish Chaterjee