XML
  Home arrow XML arrow Page 6 - 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 
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 - 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=
    "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:element name="ResAddress">
                                                <xs:complexType>
                                                          <xs:attributeGroup ref="attrAddress" />
                                                </xs:complexType>
                                          </xs:element>
                                    </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:attributeGroup name="attrAddress">
            <xs:attribute name="Street" type="xs:string" />
            <xs:attribute name="City" type="xs:string" />
            <xs:attribute name="Zip" type="xs:string" />
      </xs:attributeGroup>
    </xs:schema>

    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" />
          </xs:attributeGroup>

    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:complexType>
                      <xs:attributeGroup ref="attrAddress" />
                </xs:complexType>
          </xs:element>

    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
    Settings\Administrator\Desktop\Employees.xsd
    ">
          <Employee>
                <ID/>
                <Name/>
                <ResAddress Street="13-20-26" City="Bhimavaram"
     Zip="534201"/>
          </Employee>
    </Employees>

    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.

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

    XML ARTICLES

    - 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
    - Simple Web Syndication with RSS 2.0
    - Java UI Design with an IDE







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek