XML
  Home arrow XML arrow 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  
Dedicated Servers  
Actuate Whitepapers 
Moblin 
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

Introduction to Relations in XML Schema
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 6
    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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Introduction to Relations in XML Schema


    (Page 1 of 5 )

    This is the first article in a series concentrating on implementing relations for designing robust XML schema definitions.

    If you are new to XML Schema, I strongly suggest you go through my series “Designing your own XML Schema.” It will introduce you to all the necessary concepts for designing XML schemas, even if you are a beginner.

    A simple “Primary Key” in XML Schema

    What is a Primary Key?  Anyone familiar with database design would understand it right away.  A Primary Key is a special type of constraint (or restriction) which makes sure that all the values are unique and without nulls (you can forget about indexing in XML here).  This topic involves a bit of XPATH during the implementation of a primary key in XML schema. 

    For example, all the Employee IDs should never repeat and are compulsory.  How do I enforce this?  Let us look into the following complete schema which does the same.

    <?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="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:element>
                      </xs:sequence>
                </xs:complexType>
                <xs:key name="PK_Employee_Empno">
                      <xs:selector xpath=".//Employee" />
                      <xs:field xpath="Empno" />
                </xs:key>
          </xs:element>
    </xs:schema>

    The most important code fragment to concentrate on from the above schema is as follows:

                <xs:key name="PK_Employee_Empno">
                      <xs:selector xpath=".//Employee" />
                      <xs:field xpath="Empno" />
                </xs:key>

    Within the above code fragment, you can see the definition of “Key.”  I provided some name (“PK_Employee_Empno”) to identify the key.  I also specified that the element “Empno” (in “Employee” element) is the one which should be applicable for the “Key.”  You can also provide more than one element as part of the “Key,” making it a composite primary key. I examine this kind of key in the next section.

    More XML Articles
    More By Jagadish Chaterjee


       · Hello. This is another extension to the series on XML Schema. Enjoy it. If you...
     

    XML ARTICLES

    - 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
    - Creating an XUL App Installer
    - Overlays in XUL
    - Skinning Your Custom XUL Applications







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway