| Previous | Next
PointsXPaths, bare names, and child sequences can only point to entire nodes or sets of nodes. However, sometimes you want to point to something that isn't a node, such as the third word of the second paragraph or the year in a A point is identified by its container node and a non-negative index into that node. If the node contains child nodes--that is, if it's a document or element node--then there are points before and after each of its children (except at the ends, where the point after one child node will also be the point before the next child node). If the node does not contain child nodes--that is, if it's a comment, processing instruction, attribute, namespace, or text node--then there's a point before and after each character in the string value of the node, and again the point after one character will be the same as the point before the next character. Consider the document in Example 11-1. It contains a Example 11-1. A novel document<?xml version="1.0"?> <?xml-stylesheet value="novel.css"?> <!-- You may recognize this from the last chapter --> <novel copyleft="public domain"> <title>The Wonderful Wizard of Oz</title> <author>L. Frank Baum</author> <year>1900</year> </novel> There are eight points directly inside the Figure 11-1. The points inside the novel elementInside the text node child of the
Notice that the points occur between the characters of the text rather than on the characters themselves. Points are zero-dimensional. They identify a location, but they have no extension, not even a single character. To indicate one or more characters, you need to specify a range between two points. XPointer adds two functions to XPath that make it very easy to select the first and last points inside a node, xpointer(start-point(//title)) This XPointer indicates the point immediately before the xpointer(end-point(//author)) If there were multiple This XPointer points to the point immediately before the letter T in "The Wonderful Wizard of Oz": xpointer(start-point(//title/text( ))) This point falls immediately after the point indicated by To select points other than the start-point or end-point of a node, you first need to form a range that begins or ends with the point of interest using |