Home > Articles > Web Services > XML

  • Print
  • + Share This
This chapter is from the book

6.4 Using Xpointers

So far we have discussed the specifics of XPointer as a way of identifying resource fragments. In this section, we talk about some of the issues that arise when using XPointers. One of the obvious problems when creating and using XPointers in an environment that is essentially character-based is the issue of character escaping (described in section 6.4.1). Another topic of a similar nature is the question of how to use XPointers with XML Namespaces (discussed in section 6.4.2).

XPointers identify resource fragments by describing ways for locating them inside the resources. As pointed out earlier, this can be done in an endless variety of ways, so composing XPointers is not a mechanical process. Rather, it requires some intelligence in order to compose "good" XPointers. Since XPointer is a new technology, there is not much implementation experience to build on; but nevertheless in section 6.4.3 we describe some guidelines for composing good XPointers. Finally, in section 6.4.4 we look into the question of what exactly good means. In many cases, it will have a lot to do with ensuring XPointer persistence.

6.4.1 XPointer Character Escaping

While composing XPointers is based on the way subresources within XML documents should be identified, they must also be coded in a way that makes it possible to exchange and interpret them unambiguously. XPointers use a character-based notation and are thus easy to compose and read. But several characters within XPointers have special meaning and must therefore be escaped, if they have to be embedded into XPointers. Because of the di8erent standards involved when actually using an XPointer, escaping mechanisms occur on di8erent levels, as follows:

  • XPointer escaping rules. The XPointer specification defines escaping rules for some special characters. Most importantly, parentheses in XPointer must be balanced. This is because XPointer is built on the assumption that the end of syntactic constructs using parentheses can be found by identifying the balanced parenthesis. Consequently, unbalanced parentheses in XPointers must be escaped, and this is done by prefixing them with the circumflex character, "^". This makes it necessary to also escape the circumflex character, which is done by escaping it with itself (i.e., the literal circumflex character within an XPointer is written as "^^").

  • XML escaping rules. Very often XPointers will be used within XML documents, and in this case XML's rules for escaping XML special characters must be observed. This means that any characters not representable in the character encoding of the XML document (as well as any characters relevant for XML markup) must be written as character references or as predefined entity references.

  • URI escaping rules. URI references must adhere to the syntactic rules defined by RFC 2396 [Berners-Lee+ 98], which allows only a limited set of characters. All other characters must be represented using the URI escape mechanism, which represents these characters by a percent sign, "%", followed by two hexadecimal digits.

These character-escaping rules in many cases must be combined when XPointers are used in an XML-based environment. Consequently, character escaping can become quite complicated. The XPointer specification gives some examples of how the di8erent escaping mechanisms a8ect a given XPointer (reproduced in Tables 6.2 and 6.3).

Table 6.2 XPointerChar acterEscaping (Example 1)

Level

Example

Initial

xpointer(string-range(//P,"a little hat ^"))

XPointer

xpointer(string-range(//P,"a little hat ^^"))

XML

xpointer(string-range(//P,"a little hat ^^"))

URI

xpointer(string-range(//P,%22a%20little%20hat%20%5E%5E%22))


Table 6.3 XPointer Character Escaping (Example 2)

Level

Example

Initial and XPointer

xpointer(id('resum ´ e')) ´

XML

xpointer(id('résumé'))

URI

xpointer(id('r%C3%A9sum%C3%A9'))


In the first example (Table 6.2), it is interesting to see that even trivial things such as space characters must be escaped in the URI encoding because spaces are not allowed to appear literally within URIs. In the XML encoding, the double quotes must be escaped only if the XPointer appears within an XML attribute that is delimited with double quotes.

The second example (shown in Table 6.3) shows how to deal with non-ASCII characters. Because XPointer is based on Unicode, the accented letter appears both in the initial and the XPointer form. Based on the assumption that the XML document supports only ASCII, the accented letter must be represented by a character reference to its Unicode code point [Unicode 00]. In the URI encoding, however, the accented character has first to be encoded in UTF-8 [Yergeau 98] before the resulting byte sequence is escaped, so the result looks quite di8erent from the XML escaping.

6.4.2 XPointers and Namespaces

In section 6.2.3, we discussed how XPointer defines the concept of schemes (in fact, each full XPointer is nothing more than a sequence of scheme-specific parts) and that currently only the xpointer and the xmlns schemes are specified. XPath (and thus, XPointer) makes it possible to use qualified names that have a namespace prefix and a local part. (For a discussion of qualified names and XML Namespaces in general, see section 4.2.) In XML documents, the namespace prefix can easily be interpreted because, in order for the qualified name to be valid, there must be a namespace declaration associating that prefix with a namespace URI somewhere on an ancestor element.28 This is no problem since the qualified names in XML are embedded into the context provided by the XML document (in particular, the namespace declarations within this document). An XPointer, however, does not have such a context because it may be used outside any document, simply as part of a URI reference. Consequently, there must be a way to establish the context of namespace declarations for XPointers.

XPointer defines the xmlns scheme for declaring namespaces. This is, in a way, very similar to namespace declarations in XML documents. Each xmlns scheme part associates one namespace prefix with a namespace URI. However, the syntax is slightly di8erent from the one used in XML. The syntax is defined in rules 9 and 10 of the standard, as shown in section 6.2.3 (and repeated here):

Thus, whenever an XPointer is used that contains qualified names, it has to contain xmlns scheme parts for declaring the prefixes being used in the qualified names, as shown in the following example:

...#xmlns(html=http://www.w3.org/1999/xhtml)xpointer(//html:h3[9]) 

It is important to note that the prefix used in the XPointer and the prefix used in the resource need not be the same in order for the XPointer to match. The important part in this case is the namespace URI, so it is necessary only that the URI in the XPointer xmlns scheme part and the URI in the XML document (i.e., the namespace declaration using the xmlns attribute) are the same.

If two xmlns scheme parts within one XPointer declare the same prefix, then the second (i.e., right) declaration overrides the first (i.e., left) one. However, because evaluation of XPointer scheme parts is done stepwise from left to right, an xpointer scheme part that appears between the two xmlns scheme parts declaring the same prefix will be interpreted using the first declaration.

6.4.3 How to Compose XPointers

In section 5.5 we described in detail how to use XPath. The same principles apply to XPointer, particularly the key points of "being as specific as possible" and "filtering as early as possible." However, it is important to see the di8erence in possible application scenarios:

  • XPath and XSLT. Today, the most frequently used application of XPath is in XSLT. In XSLT, XPaths may be evaluated very often during the processing of a style sheet, so it is important to keep an eye on the eSciency of the XPaths being used. Furthermore, the XSLT author often also controls the XML document (as well as the schema behind it), which makes it easier to compose XPaths that are not compromised by modifications to documents or even the schema.

  • XPath and XPointer. In XPointer, however, XPath is often used for identifying fragments in resources not under the control of the XPointer's author. On the other hand, XPointers are usually evaluated only once (when locating the fragment within the resource), so eSciency is not a significant issue. Robustness, on the other hand, is very important since the XPointer should continue to work even if the resource that it points into changes.

Consequently, there is a di8erence between using XPath in the context of XSLT and using it in the context of XPointer. In general, the most important aspect of composing XPointers is robustness, which therefore is discussed separately in section 6.4.4.

As pointed out already, there are countless ways for each given fragment to be identified by an XPointer. We have already demonstrated this with the example of W3C's technical reports Web page at the start of this chapter. Continuing this discussion, we could add that, if, for example, the heading was not identified by the last-call ID, it would be possible to locate the heading based on its content,29 as shown in the following URI:

http://www.w3.org/TR#xpointer(//h3[contains(string(.),
  'Working%20Drafts%20in%20Last%20Call')/following::dl[1]/dt[7]//a) 

However, it would not make much sense to list a huge number of possible XPointers identifying the same resource because this list would never be exhaustive. Furthermore, without knowing the schemas behind the resources and the characteristics of how they are modified, it is hard to actually rate the many variants qualitatively.

The main point is that anybody involved in the creation of XPointers (either manually or programmatically) should be aware that this is not a strict science but more of an art form. In particular, any software generating XPointers should be carefully designed in order to generate good XPointers, and doing this is a non-trivial task. The quality criteria depend on the application domain and on how much knowledge there is available about the resources being used. In particular, one criterion that will very often be highly ranked is the persistence of XPointers.

6.4.4 Persistence

As discussed in the introduction to this chapter, the persistence of an XPointer is a serious issue (see also the discussion in section 3.3.2). Even if the resource addressed by a URI is still available, it may have changed, and the XPointer may not work any more, or it may not work as expected. In order to construct robust XPointers (i.e., XPointers that are tolerant against modifications of the resource), it is necessary to follow some guidelines. These guidelines, however, depend on how much is known about the resources being used.

As an example, it is fairly certain that the W3C will keep its overall structure of the technical reports page (see Figure 6.1), and that additions to the individual sections (e.g., "Working Drafts in Last Call") will always be at the start of the section. It would therefore be a reasonable idea to use a section's ID and to then start to count from the end of the list contained within the following:

http://www.w3.org/TR#xpointer(id('last-call')/ 
  following::dl[1]/dt[last()-4]//a) 

While this approach could (and probably would) work within the "Recommendations" or "Notes" sections (where documents remain), it is less likely to work in the "Working Drafts in Last Call" section where working drafts may change status and may be deleted. By now it should be clear that constructing robust XPointers requires a good deal of knowledge about the resources, which may be impractical or too expensive to acquire.

Using IDs is always a good idea; and as long as there are IDs being used within the resource, it is a good idea to start with an ID and then navigate from there. But again, if the schema of a resource is unknown, then it is not really possible to find out which attributes are used as IDs. (However, it may be possible to make an educated guess, such as looking for attributes with unique values or attributes having the string id as part of their name.)

Besides all these worries about XPointers becoming invalid or incorrect because of resource modifications, it should always be remembered that even though XPointer is the W3C standard for XML fragment identification, it is not the only means of identifying fragments. If, for example, the validity of fragments is very important, then one alternative might be not only to generate XPointers but also to generate information for checking the XPointer's validity. One approach to this might be to use the modification time of the resource at the time the XPointer was generated, or even a digital fingerprint of the resource or subresource (using checksum algorithms such as MD5 [Rivest 92] or SHA [NIST 93]).

Information such as dates or checksums could easily be incorporated into XPointers themselves by using proprietary schemes, which, by defini-tion, would be ignored by applications not knowing or supporting them. That way it would be possible to generate XPointers that would work on all platforms supporting XPointer and that would have the added benefit of being able to be tested for possible modifications of the fragment by platforms supporting the additional XPointer scheme.

  • + Share This
  • 🔖 Save To Your Account

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.

Overview


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.

Surveys

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.

Newsletters

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.

Security


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

Children


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

Marketing


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.

Choice/Opt-out


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.

Links


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