Home arrow XML arrow Page 6 - 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 - Attribute Groups in XML Schema
(Page 6 of 6 )

This concept is very similar to “groups” in XML Schema (as described in the previous section).  The only difference is that, instead of defining elements inside the group (as in the previous section), we define frequently repeated attributes within the group, forming an “attribute group.”

Once an “Attribute Group” is defined with its own name, it can be applied at several instances within the same schema (or even external schemas as well).  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=
  <xs:element name="Employees">
              <xs:documentation>Contains All Employee information</xs:documentation>
                    <xs:element name="Employee" maxOccurs="unbounded">
                                      <xs:element name="ID" type="xs:string" />
                                      <xs:element name="Name" type="xs:string" />
                                      <xs:element name="ResAddress">
                                                      <xs:attributeGroup ref="attrAddress" />
        <xs:key name="PK_Employee_ID">
              <xs:selector xpath=".//Employee" />
              <xs:field xpath="ID" />
  <xs:attributeGroup name="attrAddress">
        <xs:attribute name="Street" type="xs:string" />
        <xs:attribute name="City" type="xs:string" />
        <xs:attribute name="Zip" type="xs:string" />

The most important fragment to be concentrated on is the following:

      <xs:attributeGroup name="attrAddress">
            <xs:attribute name="Street" type="xs:string" />
            <xs:attribute name="City" type="xs:string" />
            <xs:attribute name="Zip" type="xs:string" />

The above defines that there exists three attributes, “Street,” “City” and “Zip” which are together grouped (or encapsulated) as “attrAddress.”  The following code snippet makes use of it accordingly when necessary:

      <xs:element name="ResAddress">
                  <xs:attributeGroup ref="attrAddress" />

The above snippet defines a new element, “ResAddress,” which would have all the attributes defined within “attrAddress.”  The following is a sample XML document, which conforms to the above XML Schema:

<?xml version="1.0" encoding="UTF-8"?>
<Employees xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:noNamespaceSchemaLocation="C:\Documents and
            <ResAddress Street="13-20-26" City="Bhimavaram"

From all of the articles in this series, any reader should be confident enough to design their own pretty XML schemas very easily without many problems.  Though I didn’t touch the most advanced topics (yet), you can expect them soon.  Keep referring to this website frequently or sign up for a newsletter to find out when new articles get published.

Any comments, suggestions, feedback, bugs, errors are highly appreciated at jag_chat@yahoo.com

DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

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-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials