Connections between documents and parts of documents

Linking with XLinks and XPointers

XLink


XPointer

XML Linking Language

Framework for creating

XLink Markup Design

XLink namespace: http://www.w3.org/1999/xlink

<my:crossReference
    xmlns:my="http://example.com/"
    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">
    Current List of Students
</my:crossReference>

XLink Elements and Attributes

Extended links

Simple links

Extended links attributes

Extended links elements (title | resource | locator | arc)*

title

resource

locator

arc

Simple links attributes

xlink:type attribute

  • "simple" Creates a simple link
  • "extended" Creates an extended link
  • "locator" Creates a locator link that points to a resource
  • "arc" Creates an arc with multiple resources and various traversal paths
  • "resource" Creates a resource link, which indicates a specific resource
  • "title" Creates a title link. Such elements are useful for internationalizetion purposes.
  • The locator xlink:href attribute

    <CLASS_SLIDE xmlns:xlink="http://www.w3.org/1999/xlink"
      xlink:type="simple"
      xlink:show="new"
      xlink:href="http://www.cs.rpi.edu/~puninj/XMLJ/classes.xml#        
      				xpointer(/child::*[position()=8]/child::*[position()=first()])">
      XLinks and XPointers
    </CLASS_SLIDE>
    

    Semantic attributes xlink:role, xlink:arcrole and xlink:title

    Optional attributes

  • xlink:title - Human-readable description
  • xlink:role, xlink:arcrole - URI reference identifies some resource that describes the intended property
    <CLASS_SLIDE xmlns:xlink="http://www.w3.org/1999/xlink"
      xlink:type="simple"
      xlink:show="new"
      xlink:role="http://www.cs.rpi.edu/~puninj/XMLJ/slideroles"
      xlink:title="XLinks and XPointers"
      xlink:href="http://www.cs.rpi.edu/~puninj/XMLJ/classes.xml#        
      				xpointer(/child::*[position()=8]/child::*[position()=first()])">
      XLinks and XPointers
    </CLASS_SLIDE>
    

    Behavior attribute: xlink:show

    Behavior attribute: xlink:actuate

    Locator-type element

    <!ELEMENT person EMPTY>
    <!ATTLIST person
      xlink:type      (locator)       #FIXED "locator"
      xlink:href      CDATA           #REQUIRED
      xlink:role      CDATA           #IMPLIED
      xlink:title     CDATA           #IMPLIED
      xlink:label     NMTOKEN         #IMPLIED>
                    
    <!ELEMENT course EMPTY>
    <!ATTLIST course
      xlink:type      (locator)       #FIXED "locator"
      xlink:href      CDATA           #REQUIRED
      xlink:role      CDATA           #FIXED "http://www.example.com/linkprops/course"
      xlink:title     CDATA           #IMPLIED
      xlink:label     NMTOKEN         #IMPLIED>
    
    <person xlink:href="students/patjones62.xml"
            xlink:label="student62"
            xlink:role="http://www.example.com/linkprops/student"
            xlink:title="Pat Jones" />
    <person xlink:href="profs/jaysmith7.xml"
    	xlink:label="prof7"
    	xlink:role="http://www.example.com/linkprops/professor"
    	xlink:title="Dr. Jay Smith" />
    <course xlink:href="courses/cs101.xml"
    	xlink:label="CS-101"
    	xlink:title="Computer Science 101" />
    

    Resource-type element

    <!ELEMENT gpa ANY>
    <!ATTLIST gpa
      xlink:type      (resource)      #FIXED "resource"
      xlink:role      CDATA           #FIXED "http://www.example.com/linkprops/gpa"
      xlink:title     CDATA           #IMPLIED
      xlink:label     NMTOKEN         #IMPLIED>
    
    <gpa xlink:label="PatJonesGPA">3.5</gpa>
    

    Traversal Attributes xlink:from, xlink:to, xlink:label

    xlink:from What resource an arc comes from

    xlink:to What resource an arc goes to

    xlink:label Label of a resource of locator element

    If a value is supplied for a xlink:from or xlink:to attribute, it must correspond to the same value form some xlink:label attribute on a locator or resource element
    <!ELEMENT go EMPTY>
    <!ATTLIST go
       xlink:type      (arc)           #FIXED "arc"
       xlink:arcrole   CDATA           #IMPLIED
       xlink:title     CDATA           #IMPLIED
       xlink:show      (new|replace|embed|other|none)	#IMPLIED
       xlink:actuate   (onLoad|onRequest|other|none)	#IMPLIED
       xlink:from      NMTOKEN         #IMPLIED
       xlink:to        NMTOKEN         #IMPLIED>
    
    <go xlink:from="CS-101"
        xlink:arcrole="http://www.example.com/linkprops/auditor"
        xlink:to="student62"
        xlink:show="replace"
        xlink:actuate="onRequest"
        xlink:title="Pat Jones, auditing the course" />
    

    XPointers

    XPointer is build on top of the XML Path Language. These extensions allow:


    xlink:href="http://www.cs.rpi.edu/~puninj/XMLJ/classes.xml# xpointer(/child::*[position()=8]/child::*[position()=first()])">

    XPointers extend XPaths


    axis::node_test[predicate]

    For example:

    child::STUDENT[position() = 3]

    XPointer Axes

    XPointer Node Tests

    Creating Points

    start-point()

    For example:

    <?xml version="1.0"?>
    <BOOK>
        <P>chapter 1 - Intro</P>
        <P>chapter 2 - conclusion</P>
    </BOOK>
    

    points right before the character 'e'

        xpointer(/BOOK/P[2]/text()/start-point()[position() = 5])

    Creating Ranges

    XPointer functions

    "range-to" Function

    For each location in the context, range-to returns a range

    Example: Locates the range from the start point of the element with 
             ID "chap1" to the end point of the element with ID "chap2"
             xpointer(id("chap1")/range-to(id("chap2")))
    

    "string-range" Function

    Returns a location set with one range for every nonoverlapping match to the search string. The match operation is case-sensitive.

    Examples:
      string-range(/,"John")
      string-range(/,"John")[2]
      string-range(//STUDENT[3]/NAME, "John")[3]
      string-range(//STUDENT[3]/NAME, "John",6,2)[3]