The eXtensible Markup Language (XML)

Fragments, XLink, and XPointer

Several XML technologies are used to support linking between XML documents, pointing at parts of XML documents, and exchanging fragments of XML documents.

The XML Fragment Interchange (Candidate Recommendation, February 2001) and XML Inclusions (XInclude) (Working Draft, May 2001) are being developed by the XML Core Working Group.

The XML Linking Working Group is developing the XML Pointer Language (XPointer) (Working Draft, January 2001), the XML Linking Language (XLink) (Recommendation, June 2001), and the XML Base (Recommendation, June 2001).

XML Fragment Interchange

Fragment interchange is the process of receiving and/or parsing a fragment of XML data.  A fragment of XML data is a just a part of an XML document (meeting some restrictions) plus possibly some extra information.  The contextual  information is called a fragment specification context (fcs) and is a well-formed XML document within the fcs element.  Together, the fcs and fragment body form a

The fcs element has four optional attributes: extref for a URI of an external subset (e.g., the DTD), intref for a URI of an "externalized" internal subset, parentref for the URI of the parent document, and sourcelocn for a URI of the fragment body within the parent document.  The fcs element also provides the context of the fragment, locating it in relationship to the document tree.

The XML Fragment Interchange Recommendation has a simple example fcs in Section 5.4.

The fragment body must be well-balanced  that is if it contains any part of a markup  or other construct, it must contain all of the markup of that construct (e.g., in the case of elements, all of both the start and end tag).  A fragment body need not necessarily be well-formed.  For example, it could contain only text or multiple elements at its top level.

The fcs and the fragment body can be bundled in a package.  The Recommendation does not provide a normative specification for packaging, but they do provide a simple example package structure.  Alternatively, a fragment transmission might be asynchronous, for example, with a request for a fragment context, followed by delivery of the fragment context, followed by a possible request for the fragment body, followed by delivery of the fragment body.

The Recommendation has some other examples of the use of XML fragments.

XML Linking Language (XLink)

HTML popularized the use of hyperlinks on the Internet.  HTML hyperlinks create a connection from a part of one document to another document (which is named in a URL).  The "start" of the HTML hyperlink is visually distinguished in some fashion (e.g., with a different color and/or underlining) by the user-agent (e.g., a browser).

HTML hyperlinks have several limitations.  They are present only in the source document and there is no central point of management.  They allow only uni-directional referencing.  They connect only two resources.  They do not specify the desired behavior of the user-agent with respect to the link.

The XLink Recommendation is being developed to address some of these issues.

The XLink markup specifies the namespace attribute (http://www.w3.org/1999/xlink) and uses other attributes including type.  For example:

    <CrossRef  xmlns:xlink="http://www.w3.org/1999/xlink"
                xlink:type="simple" ... >
        ...
    </CrossRef>

XLink provides global attributes: type, href, role, arcrole, title, show, actuate, label, from, and to.  There are six types of links.  The Recommendation specifies the usage patterns for each type.

A link of simple type is similar to an HTML hyperlink and uses the optional attributes:

    href - destination URI
    role - URI describing the function of the link's content
    arcrole - URI describing the function of the link
    show - defines how content is rendered (e.g., new, replace, embed, other, none)
    actuate - defines when link is triggered (e.g., onRequest, onLoad, other, none)
    title - a human-readable string naming or describing the link

For example:

    <CrossRef xmlns:xlink="http://www.w3.org/1999/xlink"
        xlink:type="simple"
        xlink:href="students.xml"
        xlink:role="http://www.example.com/linkprops/studentlist"
        xlink:title="Student List"
        xlink:show="new"
        xlink:actuate="onRequest">
        Entry
    </CrossRef>

Some of the specifics of these attributes are discussed below.

Links of extended type allow linking of multiple objects and may be specified outside the source document.  There are three types of extended links:  inbound, outbound, and third-party.  An extended link has participants (locators and resources) and arcs.
Resources are "by-value" local resources, whereas locators use URIs in a "by-reference" manner.

Elements that have extended XLink attributes can have role and title attributes and may have sub-elements also with XLink attributes identifying them as:
    locator elements
    resource elements
    arc elements
    title elements

Locator elements appear as sub-elements of an extended XLink.  Locator elements have attributes xlink:href, xlink:role, xlink:title, and xlink:label.  Only the xlink:href attribute is required.

Resource elements also appear as sub-elements of an extended Xlink.  Resource elements have optional attributes link:role, xlink:title, and xlink:label.

Arc elements define, as the name suggests, the connections between locators in an extended link.  Arc elements have optional attributes xlink:arcrole, xlink:title, xlink:show, xlink:actuate, xlink:from, and xlink:to.

An example from the book:

<family xmlns:xlink="http://www.w3.org/1999/xlink"
        xlink:type="extended"
        xlink:role="family"
        xlink:title="John Smith's family">
   <person
        xlink:type="locator"
        xlink:href="johnsmith.xml"
        xlink:label="parent"
        xlink:title="John Smith"/>
   <person
        xlink:type="locator"
        xlink:href="marysmith.xml"
        xlink:label="parent"
        xlink:title="Mary Smith"/>
   <person
        xlink:type="locator"
        xlink:href="billysmith.xml"
        xlink:label="child"
        xlink:title="Billy Smith"/>
   <person
        xlink:type="locator"
        xlink:href="kateysmith.xml"
        xlink:label="child"
        xlink:title="Katey Smith"/>
   <person
        xlink:type="locator"
        xlink:href="johnsmithjr.xml"
        xlink:label="child"
        xlink:title="John Smith Jr."/>
   <relationship
        xlink:type="arc"
        xlink:from="parent"
        xlink:to="child"
        xlink:title="See children"
        xlink:show="replace"
        xlink:actuate="onRequest"/>
</family>

Produces the following links:
    John Smith to Billy Smith
    John Smith to Katey Smith
    John Smith to John Smith Jr.
    Mary Smith to Billy Smith
    Mary Smith to Katey Smith
    Mary Smith to John Smith Jr.

The explict links are those defined by elements that have the xlink:type attribute equal to "arc".  If no arc element is included, Xlink assumes implict links between each of the locators in the extended link definition.  Some of the consideratons in the treatment of implicit and explicit arcs are not contained in the recommendation and may be left to implementations.

XLink allows out-of-line (as compared to inline) extended links.  When an arc has its arcrole set to the URL http://www.w3.org/1999/xlink/properties/linkbase, then the all simple and extended links are extracted from the named endpoint of the arc as if it were found in the linkbase.  In this, the xlink:actuate attribute must be set to onLoad.  For example,
for the textbook:

<catalogLinks
        xmlns:xlink="http://www.w3.org/1999/xlink"
        xlink:type="extended">
    <linkStart
        xlink:type="resource"
        xlink:label="catalogLink" />
    <linkDatabase
        xlink:type="locator"
        xlink:label="catalogDocument"
        xlink:href="http://www.wrox.com/Catalog/linkdb.xml" />
    <linkArc
         xlink:type="arc"
xlink:arcrole="http://www.w3.org/1999/xlink/properties/linkbase"
        xlink:from="catalogLink"
        xlink:to="catalogDocument"
        xlink:actuate="onLoad" />
</catalogLinks>

 Out-of-line links are useful for many purposes, including markup of read-only documents.

Here is an example from the textbook of using in-line links in XML data and an XSL stylesheet to transform the data to an HTML document.  XLinks are converted to HTML hyperlinks.

XPointer

HTML points to a specific location within a document using this construction:
    <a href="http://domain.tld/doc.html#place">...</a>

Two of the problems with HTML pointers are 1) that the anchor points must point to named places in the HTML document (named with the "<a name="place">" construction and 2) that the anchor points link to the whole document (and not just a piece).

The basic syntax for XPointers are similar to the HTML notation, for example:
    http://domain.tld/doc.xml#xpointer(place)
would point to the element with the ID "place" in the doc.xml file.

Fragments identifiers may be specified in three ways: bare names, child sequence, and full XPointers.

From the textbook:

<Catalog>
   <Book color="red" ID="book1">
      <Title>XML IE5 Programmer's Reference</Title>
      <Pages>480</Pages>
      <ISBN>1-861001-57-6</ISBN>
      <RecSubjCategories>
         <Category>Internet</Category>
         <Category>Web Publishing</Category>
         <Category>XML</Category>
      </RecSubjCategories>
      <Price>$29.99</Price>
   </Book>
</Catalog>

 For this example, #book1 and #xpointer(book1) are equivalent bare name pointers to the fragment consisting of the book element.

For this example, #/1/1/4/2 and #xpointer(/1/1/4/2) are equivalent child sequence pointers to the fragment consisting of second Category element.  This could also be written #xpointer(book1/4/2).

The full XPointer specification uses XPath for its location mechanism.  XPointer extends XPath with constructions for defining Points, Ranges, and other functions such as string-range.

The XPointer can also contain a namespace prefix specification.