XML
  Home arrow XML arrow Page 3 - Introduction to Relations in XML Schema
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

Introduction to Relations in XML Schema
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 7
    2006-04-17

    Table of Contents:
  • Introduction to Relations in XML Schema
  • A composite “Primary Key” in XML Schema
  • Combining two different roots or hierarchies in a single XML Schema: the problem
  • Combining two different roots or hierarchies in a single XML Schema: the solution
  • Defining a simple relation in XML Schema: XML Schema example

  • 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


    Introduction to Relations in XML Schema - Combining two different roots or hierarchies in a single XML Schema: the problem


    (Page 3 of 5 )

    This was one of the main problems I faced earlier while designing an XML schema.  An XML schema supports opening up several root elements (with their own primary keys).  But an XML document would never permit it!  A proper XML document should always be defined with only one root element. 

    To understand this, let us consider that I would like to have two hierarchies within a single XML document.  The first focuses on “dept” and the other on “emp.”  Let us consider the following XML 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="Dept">
                <xs:complexType>
                      <xs:sequence>
                            <xs:element name="Deptno" type="xs:int" />
                            <xs:element name="Dname" type="xs:string" />
                            <xs:element name="Loc" type="xs:string" />
                      </xs:sequence>
                </xs:complexType>
                <xs:key name="PK_Dept_Deptno">
                      <xs:selector xpath="." />
                      <xs:field xpath="Deptno" />
                </xs:key>
          </xs:element>
          <xs:element name="Employee">
                <xs:complexType>
                      <xs:sequence>
                            <xs:element name="Empno" type="xs:int" />
                            <xs:element name="Ename" type="xs:string" />
                            <xs:element name="Sal" type="xs:float" />
                            <xs:element name="Deptno" type="xs:int" />
                      </xs:sequence>
                </xs:complexType>
                <xs:key name="PK_Employee_Empno">
                      <xs:selector xpath="." />
                      <xs:field xpath="Empno" />
                </xs:key>
          </xs:element>
    </xs:schema>

    From the above schema, you can understand that the schema allows both “dept” and “employee.”  But if you try to create an XML document based on the above schema (with both “dept” and “employee”), the parser would return an error!

    Any well-defined XML document could start with only one root element, not more than that.  So, from the above case, we can start with either “dept” or “employee,” but not both.  This raises a problem when defining a schema (with both “dept” and “employee”) to support with XML.

    The problem can be easily solved by embedding both of the hierarchies under a single root element!  The next section shows you how to do this.

    More XML Articles
    More By Jagadish Chaterjee


       · Hello. This is another extension to the series on XML Schema. Enjoy it. If you...
       · Thank You Mr. Jagadish. This was of great help to me.
       · hi jeagthesh, i am karthikeyan. i am doing xml schema related project. i am new...
       · Hi jagdeesh you really made the complex thing simple with your amazing presentation...
     

    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