XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
RE: [xml-dev] 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:

    <BookStore>
        <Book>
          ...
        </Book>
        <Book>
          ...
        </Book>
    </BookStore>

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">
        ...
    </Lot>
    <Picker id="John" locatedOn="1">
        ...
    </Picker>

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:complexType>
             <xsd:sequence>
                 <xsd:element name="Books">
                     <xsd:complexType>
                         <xsd:sequence>
                             <xsd:element ref="Book" maxOccurs="unbounded"/>
                         </xsd:sequence>
                     </xsd:complexType>
                 </xsd:element>
                 <xsd:element ref="GuestAuthors"/>
             </xsd:sequence>
        </xsd:complexType>
        <xsd:key name="PK">
            <xsd:selector xpath="bk:Books/bk:Book"/>
            <xsd:field xpath="bk:ISBN"/>
        </xsd:key>
        <xsd:keyref name="isbnRef" refer="PK">
            <xsd:selector xpath="bk:GuestAuthors/bk:Author/bk:BookForSigning"/>
            <xsd:field xpath="bk:ISBN"/>
        </xsd:keyref>
    </xsd:element> 


--> 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";
            targetNamespace="http://www.books.org";
            xmlns:bk="http://www.books.org";
            elementFormDefault="qualified">

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

        <element name="Book">
        ...

    </schema>

These two expressions:

    ref="bk:Book"
    name="Book"

are connected by the shared QName:

    {http://www.books.org}Book


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

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

Specifically, these two expressions:

    select="bk:bookstore" 
    match="bk:bookstore"

are connected by the shared QName:

    {http://www.bookstore.org}bookstore


-------------------
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">
    ]>
    <BookStore>
        
        &Siddhartha;

    </BookStore>

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 />
        </xi:include>

    </BookStore>


--> 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";
                targetNamespace="http://www.camera.org";
                xmlns:nikon="http://www.nikon.com";
                xmlns:olympus="http://www.olympus.com";
                xmlns:pentax="http://www.pentax.com";
                elementFormDefault="qualified">

        <xsd:import namespace="http://www.nikon.com";
                    schemaLocation="Nikon.xsd"/>
        <xsd:import namespace="http://www.olympus.com";
                    schemaLocation="Olympus.xsd"/>
        <xsd:import namespace="http://www.pentax.com";
                    schemaLocation="Pentax.xsd"/> 

        . . .

    <xsd:schema> 


--> 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">
       ...
    </xsl:for-each>


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

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

    doc('FitnessCenter2.xml')


/Roger



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


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS