XPointer is a W3C proposed standard for the addressing of arbitrary fragments of XML documents. XPointer extends XPath, which is used to address nodes, and adds support for single positions within a text node (the so-called points) and ranges within and across element nodes.
Our implementation is a part of a larger project called XLinkproxy, a distributed linking system based on the W3C XLink recommendation. XLink is a sophisticated linking language that uses XPointer to identify the end-points of the links, especially when they are not whole nodes of the XML tree.
Since the XLinkproxy project focuses on the linking system, the current implementation of XPointer is functional to that purpose, and is only partial in terms of the XPointer language itself. Nonetheless, many of the core functions have been implemented and tested for the linking system.
The current version of the XPointer package can be downloaded here
This XPointer library is designed to run on a web server (specifically Microsoft IIS 5.0) and it is written in Microsoft JScript 5.5. It is aimed at being hosted inside an ASP file on the server. It is based on Microsoft XML4.0 and lies on top of Microsoft's implementation of XPath.
We restrict ourselves to XPointer expressions of this kind:
XPointerExpr := ((XPathExpr)*(XPointerKeyword)*(XPathExpr)*)* XPathExpr := any XPath expression XPointerKeyword := 'point()'|'range()'|'range-to'|'range'| 'string-range'|'range-inside'| 'start-point'|'end-point'|'here()'|'origin()'
The XPointer library can be ideally divided in four parts:
Following the W3C specifications, the Location, Point e Range objects have been implemented (Node is already included in XPath).
The recursive function selectLocations handles the interpretation of an XPointerExpr.
Suppose you have an XPointerExpr such as/fender/guitars/string-range(.,'telecaster',2,4)
The selectLocations function searches for an XPointerKeyword. In this case it finds string-range, so it gets its arguments, it executes a call to selectNodes (from the XPath library) with the initial string (i.e. /fender/guitars) as its argument. Then it evaluates the XPointer expression with another call to selectLocations with this XPath as the Context. When this call returns, the procedure implementing the string-range functionality is called.
Then the XPointerExpr is cut (i.e. the resolved part is consumed). In our example the execution of the parsing function would stop because XPointerExpr is empty. If it were not empty the parsing function would have gone on with other calls to itself.
If no XPointerKeywords are found the function simply evaluates an XPath expression.
If an XPathExpr is found after an XPointerKeyword, a call to the procedure that handles the axis for point and range might appear in the chain of recursion.
As mentioned, we focused our attention on the linking system so the functions in this set are simplified and incomplete. We plan to complete the library as soon as possible. In the source code we provide details about the missing details in the implementation.
The goal of this library is to give a taste of XPointer functionalities inside an XLink engine. Our working prototype impressed us for the power of the XPointer language even though our implementation is far from being fully compliant with the current specifications.