Home arrow XML arrow One-One, One-Many and Many-Many Relations in XML Schema
SEARCH DEVARTICLES

One-One, One-Many and Many-Many Relations in XML Schema
(Page 1 of 6 )

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

If you are new to relations, I strongly suggest you refer to my first article in the same series, "Introduction to Relations in XML Schema."

Implementing a “One to One” relation in XML Schema: the schema

Since I already introduced the topic of “relations in XML Schema” in my previous article, I don’t think it is necessary to define or explain it here. Concepts such as primary key, composite primary key, simple relations, and so on are already covered in the previous article of this series.

Now, we shall examine the concept of a one to one relation.  A one to one relation means that only one element can occur in a child table to the corresponding element in a parent table (in RDBMS).  The same concept is used in XML Schema as well.  The only difference is that instead of “tables” we have “element hierarchies” here. 

Let us try the code first:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
 elementFormDefault="qualified" attributeFormDefault=
"unqualified">
      <xs:complexType name="typePersonal">
            <xs:sequence>
                  <xs:element name="Empno" type="xs:int" />
                  <xs:element name="FirstName"
 type="xs:string" />
                  <xs:element name="LastName" type="xs:string" />
                  <xs:element name="DOB" type="xs:date" />
            </xs:sequence>
      </xs:complexType>
      <xs:complexType name="typeAddress">
            <xs:sequence>
                  <xs:element name="Empno" type="xs:int" />
                  <xs:element name="Street" type="xs:string" />
                  <xs:element name="City" type="xs:string" />
                  <xs:element name="ZIP" type="xs:string" />
            </xs:sequence>
      </xs:complexType>
      <xs:element name="Organization">
            <xs:complexType>
                  <xs:sequence>
                        <xs:element name="Employee"
 maxOccurs="unbounded">
                              <xs:complexType>
                                    <xs:sequence>
                                          <xs:element
 name="PersonalDetails" type="typePersonal" maxOccurs="1"
 minOccurs="1" />
                                          <xs:element
 name="AddressDetails" type="typeAddress" maxOccurs="1"
 minOccurs="0" />
                                    </xs:sequence>
                              </xs:complexType>
                        </xs:element>
                  </xs:sequence>
            </xs:complexType>
            <xs:key name="PK_Employee">
                  <xs:selector xpath=".//Employee" />
                  <xs:field xpath="PersonalDetails/Empno" />
            </xs:key>
            <xs:key name="PK_Employee_Address">
                  <xs:selector xpath=".//AddressDetails" />
                  <xs:field xpath="Empno" />
            </xs:key>
            <xs:keyref name="EmployeeAddressDetails"
 refer="PK_Employee">
                  <xs:selector xpath=".//AddressDetails" />
                  <xs:field xpath="Empno" />
            </xs:keyref>
      </xs:element>
</xs:schema>

As the code is a bit lengthy, I would like to explain the above XML Schema in the next section.


blog comments powered by Disqus
XML ARTICLES

- 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 
Support 

Developer Shed Affiliates

 




© 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials