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

One-One, One-Many and Many-Many Relations in XML Schema - Implementing a “One to One” relation in XML Schema: a sample XML document
(Page 3 of 6 )

In the previous section, I defined an XML Schema to enforce a one to one relation in between two element hierarchies.  The following would be an XML document sample for the previously defined XML Schema.

<?xml version="1.0" encoding="utf-8"?>
<Organization>
      <Employee>
            <PersonalDetails>
                  <Empno>1001</Empno>
                  <FirstName>Jagadish</FirstName>
                  <LastName>Chatarji</LastName>
                  <DOB>1978-06-25</DOB>
            </PersonalDetails>
            <AddressDetails>
                  <Empno>1001</Empno>
                  <Street>13-2-26, Nallam vari thota,
Gunupudi</Street>
                  <City>Bhimavaram</City>
                  <ZIP>534201</ZIP>
            </AddressDetails>
      </Employee>
      <Employee>
            <PersonalDetails>
                  <Empno>1002</Empno>
                  <FirstName>Winner</FirstName>
                  <LastName></LastName>
                  <DOB>1985-09-08</DOB>
            </PersonalDetails>
            <AddressDetails>
                  <Empno>1002</Empno>
                  <Street>some address</Street>
                  <City>some city</City>
                  <ZIP>some zip</ZIP>
            </AddressDetails>
      </Employee>
</Organization>

The above XML document is error free, as the values in the “Empno” element of “AddressDetails” exist in the “Empno” element of “PersonalDetails.”  Try to change “1002” (in “AddressDetails”) to “1003” (which does not exist in “PersonalDetails”).  The XML document becomes invalid during parsing!

There is another issue to remember about the “Employee” element.  I just meant it to separate the employee details only for the sake of explanation.  It would be more practical if we remove “Employee” and directly have “PersonalDetails” and “AddressDetails” under the root element “Organization.”


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-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials