Home arrow XML arrow Page 5 - Designing Your Own XML Schema: Indicators

Designing Your Own XML Schema: Indicators

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.

Author Info:
By: Jagadish Chaterjee
Rating: 5 stars5 stars5 stars5 stars5 stars / 9
March 27, 2006
  1. · Designing Your Own XML Schema: Indicators
  2. · The Choice indicator in XML Schema
  3. · The Sequence indicator in XML Schema
  4. · The maxOccurs and minOccurs indicators in XML Schema
  5. · Groups in XML Schema
  6. · Attribute Groups in XML Schema

print this article

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 us consider the following example:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
 elementFormDefault="qualified" attributeFormDefault=
  <xs:element name="Employees">
             <xs:documentation>Contains All Employee
                    <xs:element name="Employee"
                                      <xs:element name="ID"
 type="xs:string" />
                                      <xs:element name="Name"
 type="xs:string" />
                                      <xs:group ref="Address" />
        <xs:key name="PK_Employee_ID">
              <xs:selector xpath=".//Employee" />
              <xs:field xpath="ID" />
  <xs:group name="Address">
              <xs:element name="Street" type="xs:string" />
              <xs:element name="City" type="xs:string" />
              <xs:element name="Zip" type="xs:string" />

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:element name="Street" type="xs:string" />
                  <xs:element name="City" type="xs:string" />
                  <xs:element name="Zip" type="xs:string" />

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
            <Street>13-20-26, gunupudi</Street>

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).

blog comments powered by Disqus

- Open XML Finally Supported by MS Office
- XML Features Added to Two Systems
- Using Regions with XSL Formatting Objects
- Using XSL Formatting Objects
- More Schematron Features
- Schematron Patterns and Validation
- Using Schematron
- Datatypes and More in RELAX NG
- Providing Options in RELAX NG
- An Introduction to RELAX NG
- Path, Predicates, and XQuery
- Using Predicates with XQuery
- Navigating Input Documents Using Paths
- XML Basics
- Introduction to XPath

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials