[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Relationships [was RE: James Clark: XML versus theWeb]

  • From: "Costello, Roger L." <costello@mitre.org>
  • To: "xml-dev@lists.xml.org" <xml-dev@lists.xml.org>
  • Date: Tue, 7 Dec 2010 16:49:38 -0500

RE:  Relationships [was RE: James Clark: XML versus theWeb]
Hi Folks,

Issue: How should relationships be expressed in the next generation of XML?

Here are the problems with the relationship mechanisms provided by today's XML technologies:  

1. Some relationships are implicit and subject to various interpretations. That's not good for data interoperability.

2. There are many different relationship mechanisms. This makes it difficult to learn the XML technologies. 

3. The relationships have limited expressiveness. For example, none of the XML technologies provide a built-in way to express the relationship "A is similar to B."

Can we devise a single, simple, powerful mechanism for expressing relationships? What are the desired characteristics of such a mechanism?

Relationship Mechanisms in Today's XML Technologies

Hierarchical Containment Relationships

Consider this XML snippet:


The snippet shows a relationship between BookStore and Book; namely, BookStore consists of Books. The relationship is implicit and may be interpreted in different ways. 

This hierarchical containment relationship is provided by the XML specification.

Primary Key/Foreign Key Relationships

There are multiple mechanisms for expressing primary key/foreign key relationships.

--> The XML ID/IDREF Mechanism <--

Consider this XML snippet:

    <Lot id="1">
    <Picker id="John" locatedOn="1">

The snippet shows a relationship between Picker John and Lot 1; namely, Picker John is located on Lot 1. This is employing the ID/IDREF relationship mechanism provided by the XML specification.

--> The XML Schema key/keyref Mechanism <--

XML Schema provides a primary key/foreign key relationship with the <key> and <keyref> elements. Here is an example of the key/keyref mechanism:

    <xsd:element name="Library">
                 <xsd:element name="Books">
                             <xsd:element ref="Book" maxOccurs="unbounded"/>
                 <xsd:element ref="GuestAuthors"/>
        <xsd:key name="PK">
            <xsd:selector xpath="bk:Books/bk:Book"/>
            <xsd:field xpath="bk:ISBN"/>
        <xsd:keyref name="isbnRef" refer="PK">
            <xsd:selector xpath="bk:GuestAuthors/bk:Author/bk:BookForSigning"/>
            <xsd:field xpath="bk:ISBN"/>

--> The XML Schema QName Mechanism <--

In XML Schema one element is connected (related) to another element through a shared QName. In the following example this Book element 

    <element name="Book">

is referenced from within BookStore:

    <?xml version="1.0"?>
    <schema xmlns="http://www.w3.org/2001/XMLSchema"

        <element name="BookStore">
                    <element ref="bk:Book" maxOccurs="unbounded"/>

        <element name="Book">


These two expressions:


are connected by the shared QName:


--> The XSLT QName Mechanism <--

XSLT also employs QNames to connect one part of a document to another. For example, these two templates are connected by a QName:

    <xsl:template match="/">
         <xsl:apply-templates select="bk:bookstore" />

    <xsl:template match="bk:bookstore">

Specifically, these two expressions:


are connected by the shared QName:


Cross-Document URIs

There are multiple mechanisms for expressing relationships across documents.

--> External Entities <--

Consider this XML document:

    <?xml version="1.0"?>
    <!DOCTYPE BookStore [
        <!ENTITY Siddhartha SYSTEM "Siddhartha.xml">


This is called an external entity declaration:

    <!ENTITY Siddhartha SYSTEM "Siddhartha.xml">

The external file is Siddhartha.xml. The external file may be either local or on the network. External entities are specified by the XML specification and enables relationships across documents.

--> XInclude <--

XML Include is another cross-document relationship mechanism. Here's an example:

    <?xml version="1.0"?>
    <BookStore xmlns:xi="http://www.w3.org/2001/XInclude">

        <xi:include href="Siddhartha.xml" parse="xml">
            <xi:fallback />


--> XML Schema import and include <--

The XML Schema <import> and <include> elements are mechanisms for expressing cross-document relationships. Here's an example that illustrates the import mechanism:

    <?xml version="1.0"?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"

        <xsd:import namespace="http://www.nikon.com"
        <xsd:import namespace="http://www.olympus.com"
        <xsd:import namespace="http://www.pentax.com"

        . . .


--> The XSLT document() Function <--

The XSLT document() function is a mechanism for expressing cross-document relationships. Here's an example:

    <xsl:for-each select="document('bookstore2.xml')//book">

--> The XPath doc() Function <--

The XPath doc() function is a mechanism for expressing cross-document relationships. Here's an example:



[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.

Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.