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.
Designing Your Own XML Schema: Indicators - Groups in XML Schema (Page 5 of 6 )
This is another interesting concept within XML Schema. It allows us to “group” a set of frequently used elements and refer to them in any XML Schema with a simple “ref” keyword. It is another way of linking elements apart from the “user-defined complex type,” which I explained in my previous article.
Every “group” (or set of elements) needs to be named so that it could be referred to with the keyword “ref.” You can also have additional elements to be defined apart from the substitution of all the elements in the referred group.
Let me explain the most important code fragments from the above schema. First of all let us consider the following code fragment:
<xs:group name="Address">
<xs:sequence>
<xs:element name="Street" type="xs:string" />
<xs:element name="City" type="xs:string" />
<xs:element name="Zip" type="xs:string" />
</xs:sequence>
</xs:group>
The above declares a “group” named with “Address.” “Address” is a group equipped with three elements, namely “Street,” “City” and “Zip”.
<xs:group ref="Address" />
The above statement makes all the elements available in “Address” be present (or replaced) within the same place by replacing the same statement. To understand the above statement better, you can look at the sample XML document, which conforms to the above schema:
<?xml version="1.0" encoding="UTF-8"?>
<Employees xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="C:\Documents and Settings\Administrator\Desktop\Employees.xsd">
<Employee>
<ID>1001</ID>
<Name>Jagadish</Name>
<Street>13-20-26, gunupudi</Street>
<City>Bhimavaram</City>
<Zip>534201</Zip>
</Employee>
</Employees>
From the above XML document, you can understand that it is very similar to declaring individually (but we made it as a group to reuse it at several locations).