XML
  Home arrow XML arrow Page 5 - Designing Your Own XML Schema: Indicators
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
XML

Designing Your Own XML Schema: Indicators
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 5
    2006-03-27

    Table of Contents:
  • Designing Your Own XML Schema: Indicators
  • The Choice indicator in XML Schema
  • The Sequence indicator in XML Schema
  • The maxOccurs and minOccurs indicators in XML Schema
  • Groups in XML Schema
  • Attribute Groups in XML Schema

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    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=
    "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"
     maxOccurs="unbounded">
                              <xs:complexType>
                                    <xs:sequence>
                                          <xs:element name="ID"
     type="xs:string" />
                                          <xs:element name="Name"
     type="xs:string" />
                                          <xs:group ref="Address" />
                                    </xs:sequence>
                              </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: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>
    </xs:schema>



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

    More XML Articles
    More By Jagadish Chaterjee


       · Hello guys, this is another extension for my "XML Schema" series. enjoy!
     

    XML ARTICLES

    - 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
    - Simple Web Syndication with RSS 2.0
    - Java UI Design with an IDE
    - UI Design with Java and XML Toolkits
    - Displaying ADO Retrieved Data with XML Islan...
    - Widget Walkthrough
    - Introduction to Widgets
    - The Why and How of XML Data Islands






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT