What is XPointer?
The extended links of XLink (XML Linking Language) are clearly more expressive than the the HTML links, as it can be seen in the last paragraph. They offer a lot more functionality than simple connections, as their HTML counterparts are. But the XPath-based (XML Path Language) XPointer (XML Pointer) Language extends the abilities of XLink by making a more accurate access possible. This is done by using XPointer expressions which follow the fragment identifier of XLink expressions; and they are more than simple XPath expressions, but this is shown later on.
The structure of XPointer (source: W3C):
| [2] | ChildSeq |
::= | Name? ('/'
[1-9] [0-9]* )+ |
|
| [3] | FullXPtr |
::= | XPtrPart (S?
XPtrPart)* |
|
| [4] | XPtrPart |
::= | 'xpointer' '(' XPtrExpr ')' |
|
| 'xmlns' '(' XPtrNsDecl? ')' |
||||
| Scheme '(' SchemeSpecificExpr
')' |
||||
| [5] | Scheme |
::= | NCName |
|
| [6] | SchemeSpecificExpr |
::= | StringWithBalancedParens |
|
| [7] | StringWithBalancedParens |
::= | [^()]* ('(' StringWithBalancedParens
')' [^()]*)* |
[VC: Parenthesis escaping] |
| [8] | XPtrExpr |
::= | Expr |
[VC: Parenthesis escaping] |
| [9] | XPtrNsDecl |
::= | NCName
S? '=' S?
XPtrNsURI |
|
| [10] | XPtrNsURI |
::= | Char* |
[VC: Parenthesis escaping] |
| [VC: Namespace Name] |
As already explained, the XPointer simply follows an URI (Uniform Ressource Identifier) and a number sign ("#"), whereas the XPointer has three possible forms:
The first form is a bare name, which allows an analog behaviour compared to HTML fragment identifiers. Furthermore this form encourages the use of IDs, because it has exact the same meaning as using the provided id() function. Therefore the following two examples are equivalent (only the XPointer are shown):
| item | selects the XML information, identified by the ID item |
| xpointer(id("item")) | selects the XML information, identified by the ID item |
The second form is a child sequence, which means a step-for-step navigation through the document. A look at rule [2] shows an optional name at the beginning, which is a (just explained) bare name, followed by numbers in arbitrary amounts, which are divided by slashes ("/"). The following two examples should make it easier to understand (only the XPointer are shown):
| /1/3/2 | selects the 2nd child of the 3rd child of the document element |
| item/2/1 | selects the 1st child of the 2nd child of the XML information, identified by the ID item |
The third form is a full XPointer, which consists of at least one XPointer part with optional whitespaces between the part (see here rule [3]). This part has three possible forms (see here rule [4]). The first one is the standard XPointer scheme, which contains itself an XPointer expression (rule [8]). An also possible content is the xmlns scheme, which is a namespace scheme and contains an optional XPointer namespace declaration (rule [9]). And the last choosable content is a new defined scheme with a contained specific expression (rule [6]).
For further information about the standard expressions and functions and the XPointer specific expressions and additional functions, please reference the links in the rules and the latest XPointer Working Draft (some extra functionality is explained in the next paragraph). The following table shows some full XPointer examples for additional information (only the XPointer are shown):
| xpointer (chapter/paragraph[position() = last() and @important='true']) | this full XPointer selects the last paragraph of a chapter but only, if it contains an attribute important with the value true |
| xpointer(id("chap1")/child::par[first()] to id("chap2")/child::par[last()]) | this line selects all XML information between the first par child of the element with the ID chap1 and the last par child of the element with the ID chap2 |
|
xmlns(w3=http://www.w3c.org) xpointer(//w3:elem) |
these combined XPointer parts address the information contained by the
namespace w3 in the following XML fragment
<main> |
As shown in the examples, the axes are used in the same way as they are used in XPath (for more detailed information, please reference //root/what_is_xpath). However, XPointer knows more than the simple nodes which XPath is able to handle. The following terms are necessary to understand the access capabilities of XPointer:
| point | a specific position in an XML document |
| range | all information between two points |
| location | a collective name for node, point and range |
| location-set | corresponding to the node-set which is produced by XPath expression, this is an ordered list of locations |
| singleton | a special location-set only containing one location (point and range are always singleton) |
| sub-resource | a specific part of a referenced resource (e.g. one special element) |
The previous table shows all constructs which can be addressed by XPointer; these are on the one hand more generalized, and on the other hand more detailed parts of an XML document, compared to document fragments, selected by an XPath expression (the following graph visualizes the meaning of a range):

(modified graph from: Henning Behme & Stefan Mintert, "XML in der Praxis", Addison-Wesley, 2000)
For more detailed information about XPointer, please follow the links below.
| the XPointer definition |