Home > Articles > Web Services > XML

XML Pointer Language  XPointer

Using XPointer, it is possible not only to link complete resources but also to create links between parts of resources. Learn about XPointer data models, forms, functions, and uses.
This chapter is from the book

XPath, described in detail in the previous chapter, provides a common foundation for other standards that need to address into XML documents. One such standard, and the most interesting with regard to implementing hypermedia based on XML technologies, is the XML Pointer Language (XPointer) [DeRose+ 01a], which is used for fragment identifiers for XML resources. According to RFC 3023 [Murata+ 01], XML documents are associated with a number of MIME types.1 For all these di8erent types of XML resources, it is possible to specify a fragment identifier, which is separated from the URI of the resource itself by a crosshatch (#) character. As defined in RFC 2396 [Berners-Lee+ 98] (the standard for URI syntax), a fragment identifier is not an actual part of a URI but is often used in conjunction with one in the so-called URI reference.

Thus, XPointer can be used for specifying references that point to parts of an XML document, and not to the whole document. As a simple example, while the URI http://www.w3.org/TR/ references the technical reports page of the W3C (as shown in Figure 6.1), the URI reference http://www.w3.org/TR/#xpointer(id('xptr')) specifically points to the entry for the XPointer standard on that page.2 This mechanism makes it possible to create links that are much more specific than through the use of URIs only. There are, however, several things to keep in mind, as follows:

Figure 6.1Figure 6.1 Snapshot of W3C's technical reports page

  • The resource must be XML. XPointer is a mechanism for addressing into XML documents, so the resource identified by the URI must be XML.3 In the example just given, this is true since W3C makes its pages available in XHTML, the XML variant of HTML. However, the vast majority of documents on the Web are not XML, and consequently XPointer cannot be used to address into them. While it is assumed that XML resources will become more popular in the near future (in particular since XHTML is the successor of HTML), as long as non-XML browsers are still widely used,4 HTML is likely to remain the most popular language.

    As a side note, HTML also supports fragment identifiers, but they are limited to pointing to IDs only (as opposed to the XPath-based addressing capabilities of XPointer). HTML uses its own extremely simple syntax for fragment identifiers, which works by giving the ID as the fragment identifier, so the XML example just given would be equivalent to the HTML version http://www.w3.org/TR/#xptr.5 (In this case, there is a simple correspondence between the XML and the HTML fragment identifier, because both address the fragment using its ID.)

  • The resource must remain available. Of course, a fragment identifier makes sense only as long as the resource is still available. This brings up the well-known problem of broken links in the Web, and it is independent from specifying fragment identifiers. However, because fragment identifiers are often used with URIs, this issue must be addressed. Resources on the Web often have an astonishingly short life span [Dasen & Wilde 01]; and while some resources disappear (i.e., no longer exist or at least are no longer available via a known URI), others are moved to a new URI without having automatic redirections set up by the Web server operator.

  • The ID must remain the same. In cases where the fragment identifier uses an ID within the document, it will work correctly only as long as the ID remains valid within the document (and, in the example just given, continues to identify the element representing the XPointer entry within the document). However, since we do not have control over the W3C's document management and identification policy, we have no guarantee that the ID will always be the same and that it will always identify the element we want to reference. The basic dilemma behind this is that the resource (the W3C's Web page) and the reference to it (our fragment identifier) are handled by di8erent entities, which do not necessarily cooperate (or even know each other; for example, even though we know the W3C's Web pages, the W3C probably does not know that we used their ID as an example in this book).

  • The client has to support XPointers. Even if all previous requirements are satisfied (i.e., the document is XML, it is still available via the URI, and the XPointer can still be interpreted meaningfully), the application processing the URI with the fragment identifier must implement the XPointer standard. At the time of writing, this is not the case for almost all available software, though we hope this will change in the near future. In comparison to XLink and XPath, XPointer is lagging behind in the standardization process; and as long as there is no stable standard, it cannot be implemented.

    The major browsers in their most current versions (at the time of writing, Internet Explorer 5.5, Navigator 6, and Opera 5) all support XML in the sense that they are able to not only download and interpret XML documents, but also to display them using style sheet mechanisms (CSS and/or XSL). There is, however, no support for XPointer currently. Nevertheless, as soon as XPointer reaches recommendation status, we hope to see XPointer support (as well as XLink support) in the next releases of the major browsers.

These are the requirements that must be met when using XPointer. We believe that in the near future XPointer (along with many other XML-based technologies) will become widely supported and a popular technology. For an illustration of how XPointer may not only become useful for hypermedia applications (which are the focus of this book) but also for other relatively simple cases of usage, consider the following scenario:

You find an interesting quote on the Web, possibly in an XHTML resource, that you would like to send to a friend. Instead of copying the quote into an e-mail (which would mean taking the quote out of context) or simply sending the resource's URI (which would make it necessary to somehow indicate exactly which part of the resource you mean), you select the quote with the mouse and then choose the "Generate XPointer" option from your browser's menu, which automatically generates a URI reference that exactly identifies the selected quote. You paste this URI reference into the e-mail and send it to your friend. This way, you have exactly identified the quote that was important to you without taking it out of context. Upon receiving the URI reference, your friend's browser not only requests and displays the resource containing the quote but also automatically highlights the quote identified by the XPointer part of the URI reference.

This example depends on the browser's ability to generate XPointers. Ideally, it would do so in a clever way, because for each subresource there is a multitude of possibilities for creating an XPointer identifying it. We will discuss this important issue in detail later in this chapter (in sections 6.4.3 and 6.4.4), but by now it should be clear that XPointer can provide a lot of value in an XML-based Web.

We now look at the details of XPointer. Section 6.1 discusses the general data model of XPointer, which is a generalization of XPath's data model. After this introductory section, we go into the details of how XPointers may be used as fragment identifiers, described in section 6.2. The next issue is XPointer's extensions to XPath and, in particular, the additional functions that XPointer defines. These functions are discussed in section 6.3.

After this rather formal discussion of XPointer, we then spend some time considering possible usage scenarios and how XPointer may be applied in the best possible way (section 6.4). Finally, even though XPointer is a very new standard, in section 6.5 we briefly describe our view of what XPointer's future may look like.

6.1 General Model

One of the most important aspects of XPointer is that it defines a generalization of the XPath concepts of nodes, node types, and node sets (as described in section 5.1) to the XPointer concepts of locations, location types, and location sets.6 As a reminder, nodes, node types, and node sets in XPath are used to describe concepts that can be identified as nodes in a document's tree representation, as described by the XML Infoset. XPath functionality, such as filtering an axis output by predicate, is generally de-fined in terms of operations on nodes and node sets (an exception are the string functions, but these are rather limited and always operate on strings within one text node).

XPointer's goal is to define a mechanism for XML fragment identifiers. A very common usage scenario is a user selecting arbitrary document content with a mouse and then wishing to have an XPointer generated that identifies exactly that content (e.g., to use the XPointer for creating a link pointing to that content). Since this selection can span multiple elements and furthermore may start in the middle of the text of one element and end in the middle of another, it is impossible to identify this content with XPath's constructs of nodes or strings. XPointer's solution to this problem is an extension of XPath's data model, described in section 6.1.1. To make the concepts of XPointer's data model easier to understand, we give some examples in section 6.1.2 of how this model maps to real-world scenarios.

6.1.1 XPointer Data Model

XPointer generalizes the concept of XPath nodes to locations, and, in essence, this generalization defines each location to be an XPath node, a point, or a range.7 The following definitions are taken from the XPointer specification8 and show how XPath's definition of a NodeType is extended by the concepts point and range:

Based on these definitions, XPointer also defines the location set as a generalization of XPath's node set. This definition allows XPath node tests to select locations of type point and range from a location set that might include locations of all three types. All locations generated by XPath constructs are nodes, but XPointer constructs can also generate points and ranges. The concepts of points and ranges are defined in the next two sections.


A location of type point is defined by a node, called the container node, and a non-negative integer, called the index. It can represent the location preceding any individual character, or preceding or following any node in the information set constructed from an XML document. Two points are identical if they have the same container node and index. Each point can be either a node point or a character point, which are defined as follows:

  • Node point. If the container node of a point is of a node type that can have child nodes (that is, when the container node is an element node or a root node), then the index is an index into the child nodes, and such a point is called a node point. The index of a node point must be greater than or equal to zero and less than or equal to the number of child nodes of the container. An index of zero indicates the point before any child nodes, and a non-zero index n indicates the point immediately after the nth child node.

  • Character point. When the container node of a point is of a node type that cannot have child nodes (i.e., text nodes, attribute nodes, namespace nodes, comment nodes, and processing instruction nodes), then the index is an index into the characters of the string value of the node. Such a point is called a character point. The index of a character point must be greater than or equal to zero and less than or equal to the length of the string value of the node. An index of zero indicates a point immediately before the first character of the string value, and a non-zero index n indicates the point immediately after the nth character of the string value.

Figure 6.2 shows the relationship of container nodes, node points, and character points for an example of an element containing text, then another element (which also contains text), and then some more text.

Figure 6.2Figure 6.2 Container nodes, node points, and character points. Reproduced from the XPointer specification [DeRose+ 01a] by kind permission of Steven DeRose, spring 2002.

XPointer's goal is to make XPath's concepts applicable to locations and not only to nodes, and thus the following properties for applying XPath's concepts to points are defined: The self and descendant-or-self axes of a point contain the point itself. The parent axis of a point is a location set containing a single location, the container node. The ancestor axis contains the point's container node and its ancestors. The ancestor-or-self axis contains the point itself, the point's container node, and its ancestors.

The child, descendant, preceding-sibling, following-sibling, preceding, following, attribute, and namespace axes of points are always empty.


A range is defined by two points, a startpoint and an endpoint.9 A range represents all of the XML structure and content between the startpoint and the endpoint. A range whose start- and endpoints are equal is called a collapsed range. If the container node of one point of a range is a node of a type other than element, text, or root, then the container node of the other point of the range must be the same node.10 The axes of a range are identical to the axes of its startpoint.

As a side note, remember that node sets are only one of the object types defined in XPath (the others being boolean, number, and string), and the other XPath object types also exist in XPointer. However, there is one important exception, and this is the result type of a whole XPointer. While an XPath can evaluate to any object type (consider the rather simple XPath 2+3, which evaluates to a number), XPointer requires an XPointer to always evaluate to a location set (which is logical, given that there is no way that objects other than location sets could be interpreted as fragment identifiers pointing into documents).

In order to understand some of the functions XPointer provides, it is also essential to introduce the concept of the covering range. By definition, a covering range is a range that wholly encompasses a location. This means that the concept of a covering range can be applied to any location, whether it be a node, a point, or a range. Basically, a covering range is the smallest possible range covering a given location. In detail, this is defined as follows:

  • For a range location, the covering range is identical to the range.

  • For an attribute or namespace location (both node locations), the container node of the start point and end point of the covering range is the attribute or namespace location; the index of the startpoint of the covering range is 0; and the index of the endpoint of the covering range is the length of the string value of the attribute or namespace location.

  • For the root location (a node location), the container node of the startpoint and endpoint of the covering range is the root node; the index of the start point of the covering range is 0; and the index of the endpoint of the covering range is the number of children of the root location.

  • For a point location, the start- and endpoints of the covering range are the point itself.

  • For any other kind of location, the container node of the startpoint and endpoint of the covering range is the parent of the location; the index of the startpoint of the covering range is the number of preceding sibling nodes of the location; and the index of the endpoint is one greater than the index of the startpoint.

In summary, XPointer's extensions to XPath's data model include the extension of the concept of nodes and node sets to that of locations and location sets (with the location being a node, a point, or a range). XPointer also introduces the concept of a covering range to support mapping of locations to ranges. For each location, there is a well-defined covering range.

In addition to these extensions of XPath's data model, XPointer also extends the concept of document order, as introduced in section 5.1. In general, the concept is extended not only to arrange nodes in a well-defined order but also to include point and range locations. Figure 6.2 shows how the locations of a document fragment are arranged in XPointer's document order. For defining rules regarding how to determine document order, XPointer introduces the concept of an immediately preceding node and then uses it to define how every possible combination of the relevant location types (i.e., nodes, points, and ranges) have to be compared to establish the document order of these locations.

6.1.2 XPointer Data Model Examples

To make these abstract definitions more understandable, we give some examples of how the concepts of locations, points, ranges, and nodes relate to each other. Our scenario is a browser that allows a user to create XPointers by selecting content with a mouse and then using a menu option for generating an XPointer identifying that content.

Marking a Point Within a Document

The simplest use is to mark a point within the document and generate an XPointer for this point (e.g., for creating an XPointer that is attached to an e-mail saying "please insert your text here"). To do this, the browser generates an XPointer that is a point. Depending on where the point has been selected, it is either a node point (if it has been marked within the root node or an element node) or a character point (in all other cases). Depending on how the browser was implemented, di8erent XPointers that refer to the same point could be created. Consider the case where a user selects the point before the first character of a paragraph. Depending on the browser's implementation, this could result in the following:

  • a node point into the paragraph's parent element node, identifying the point before the paragraph child,

  • a node point with index zero within the paragraph's element node, or

  • a character point with index zero within the text node of the paragraph's text.

All these cases make sense. In the first, the point could be used to insert elements before the paragraph element. In the second, the point could be used to insert elements into the paragraph before the first character; while in the third, it could be used to insert characters before the first character within the paragraph's text. It is entirely dependent on the implementation and application how these cases should be treated. Indeed, one possibility would be for the browser to present the user with a choice as to which is the appropriate XPointer.11

Selecting text within one node is the equivalent of selecting two points,12 the start and the end point of the selection, that lie inside the same node (e.g., the same element, attribute, or comment). From the user's point of view, it may not be apparent whether or not the two points are located within the same node (e.g., if two elements are not visibly separated by any formatting); but for the browser, this is easy to determine. Based on the selection of the user, the browser generates an XPointer defining a range between the selected start and end points. Since in this case the selected text lies within one node, the two points can easily be used to construct an XPointer range, which spans between the two points.

Selecting Text That Spans a Number of Nodes

If the start and the end point lie in di8erent nodes, then the range defined by the two points also spans multiple nodes. According to the range constraints defined by XPointer, this is allowed only if the containing nodes of the startpoint and the endpoint are element, text, or root nodes (in all other cases, the start and endpoint must lie within the same node). A possible selection that spans a number of nodes in the case of an XHTML-like paragraph may select text that is all inside the paragraph but still spans multiple nodes. This may be because in between there are other element nodes (e.g., nodes representing emphasized text or hyperlinks). This situation e8ectively places the start and the endpoints in di8erent text nodes (making them both children of the same paragraph node).

To further generalize this scenario, the start point and the end point may occur in entirely di8erent subtrees of the document tree, for example, within a paragraph of the first chapter and in a table cell of the third chapter. This still would represent a valid range, spanning from the character point in the text node representing the first chapter's paragraph to the node point in the table row node directly after the selected table cell.

Making Multiple Selections

Even though today's user interfaces in most cases do not support this type of interaction, it would be perfectly reasonable to implement an interface that allows multiple non-contiguous selections. This could be used to create an XPointer that references multiple ranges within the same resource (e.g., attached to an e-mail saying "what do you think about these three statements?"). In a case such as this, it is mainly a question of the design of the user interface as to how multiple selections could be implemented in a user-friendly way. From XPointer's point of view, the multiple selections could be easily combined to yield a single location set.

The preceding scenarios illustrate some typical cases in which XPointer concepts are relevant.13 So far we have not discussed how exactly the hypothetical browser maps the concepts to actual XPointers, and as a first step toward resolving this issue, we first have to discuss the possible forms of XPointers.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information

To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.


Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.


If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information

Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.


This site is not directed to children under the age of 13.


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information

If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information

Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents

California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure

Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact

Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice

We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020