XPointer
(XML Pointer Language)


XPointer

An XPointer is a reference to an element in an XML document.

XPointer use in diputree

URI encoded XPointers

XPointers are encoded in Uniform Resource Identifiers. Because the XPointer only applies to the document part of the URI it must be preceded by the document fragment identifier symbol #.

xpointer as child sequences

A child sequence locates an element by stepwise navigation using a sequence of integers separated by slashes (/). Each integer n locates the nth child element of the previously located element.

The first sequence is always /1 , which represents the document element. (bare names not supported)

xpointer with abbreviated XPath

An abbreviated XPath locates an element or elements by stepwise navigation using a sequence of element names with optional integer indexes separated by slashes (/). If the name and the index match, then the next step in the sequence is taken.

The element name can be the wildcard character (*) in which case every element is matched.

The element name can be the parent string (..) in which case the parent element is matched.

The syntax is: xpointer(abbreviated XPath)

Possible combinations

a,b and c are element names. m and n are integers.

child sequences

#/1
#/1/m
#/1/m/n

xpointer with abbreviated XPath

#xpointer(a)
#xpointer(/a)
#xpointer(/a/b)
#xpointer(/a[m])
#xpointer(a/b[m])
#xpointer(a/*/b/c[m])

Examples

Assume the following XML document

<a>          <- element 1
 <b>         <- element 2
  <c/>       <- element 3
  <c/>       <- element 4
 </b>        
 <b>         <- element 5         
  <c>        <- element 6
   <d/>      <- element 7
  </c>       
  <c/>       <- element 8
 </b>         
</a>         

#/1 refers to element 1 (the document element)
#/1/1 refers to element 2
#/1/2/1/1 refers to element 7
#/1/2/2 refers to element 8
#xpointer(/a) refers to element 1 (the document element)
#xpointer(/a/b) refers to elements 2 and 5
#xpointer(/a/b/c) refers to elements 3 and 4
#xpointer(/a/b/c[1]) refers to element 3
#xpointer(/a/b[2]/c[1]/d) refers to element 7
#xpointer(/*) refers to element 1 (the document element)
#xpointer(/*/*[2]) refers to element 5
#xpointer(/*/*[2]/c) refers to elements 6 and 8
#xpointer(/*/*) refers to elements 2 and 5
#xpointer(/a/b/c[1]/..) refers to element 2
#xpointer(/a/b[2]/c/d/../../..) refers to element 1 (the document element)

More information

http://www.w3.org/XML/ and http://www.w3.org/TR/xptr


diputree documentation © 2000 dipu