O'reilly Xpath and Xpointer.Pdf
Total Page:16
File Type:pdf, Size:1020Kb
XPath and XPointer John E. Simpson Publisher: O'Reilly First Edition August 2002 ISBN: 0-596-00291-2, 224 pages Referring to specific information inside an XML document is a little like finding a needle in a haystack. XPath and XPointer are two closely related Table of Contents languages that play a key role in XML processing by allowing developers Index to find these needles and manipulate embedded information. By the time Full Description you've finished XPath and XPointer, you'll know how to construct a full Reviews XPointer (one that uses an XPath location path to address document Reader reviews content) and completely understand both the XPath and XPointer features it Errata uses. 1 Table of Content Table of Content ............................................................................................................. 2 Preface............................................................................................................................. 4 Who Should Read This Book?.................................................................................... 4 Who Should Not Read This Book?............................................................................. 4 Organization of the Book............................................................................................ 5 Conventions Used in This Book ................................................................................. 5 Comments and Questions ........................................................................................... 6 Acknowledgments....................................................................................................... 7 Chapter 1. Introducing XPath and XPointer................................................................... 8 1.1 Why XPath and XPointer?.................................................................................... 8 1.2 Antecedents/History.............................................................................................. 9 1.3 XPath, XPointer, and Other XML-Related Specs .............................................. 12 1.4 XPath and XPointer Versus XQuery .................................................................. 15 Chapter 2. XPath Basics ............................................................................................... 17 2.1 The Node Tree: An Introduction......................................................................... 17 2.2 XPath Expressions .............................................................................................. 18 2.3 XPath Data Types ............................................................................................... 24 2.4 Nodes and Node-Sets.......................................................................................... 27 2.5 Node-Set Context................................................................................................ 38 2.6 String-Values ...................................................................................................... 40 Chapter 3. Location Steps and Paths............................................................................. 43 3.1 XPath Expressions .............................................................................................. 43 3.2 Location Paths..................................................................................................... 45 3.3 Location Steps..................................................................................................... 48 3.4 Compound Location Paths Revisited.................................................................. 63 Chapter 4. XPath Functions and Numeric Operators.................................................... 64 4.1 Introduction to Functions.................................................................................... 64 4.2 XPath Function Types......................................................................................... 66 4.3 XPath Numeric Operators................................................................................... 92 Chapter 5. XPath in Action........................................................................................... 95 5.1 XPath Visualiser: Some Background.................................................................. 95 5.2 Sample XML Document..................................................................................... 97 5.3 General to Specific, Common to Far-Out........................................................... 99 Chapter 6. XPath 2.0................................................................................................... 122 6.1 General Goals.................................................................................................... 123 6.2 Specific Requirements ...................................................................................... 126 Chapter 7. XPointer Background................................................................................ 141 7.1 XPointer and Media types................................................................................. 141 7.2 Some Definitions .............................................................................................. 143 7.3 The Framework................................................................................................. 146 2 7.4 Error Types ....................................................................................................... 147 7.5 Encoding and Escaping Characters in XPointer ............................................... 148 Chapter 8. XPointer Syntax ........................................................................................ 153 8.1 Shorthand Pointers............................................................................................ 153 8.2 Scheme-Based XPointer Syntax ....................................................................... 154 8.3 Using XPointers in a URI ................................................................................. 163 Chapter 9. XPointer Beyond XPath............................................................................ 165 9.1 Why Extend XPath?.......................................................................................... 165 9.2 Points and Ranges............................................................................................. 167 9.3 XPointer Extensions to Document Order ......................................................... 174 9.4 XPointer Functions ........................................................................................... 178 Appendix A. Extension Functions for XPath in XSLT .............................................. 187 A.1 Additional Functions in XSLT 1.0................................................................... 187 A.2 EXSLT Extensions........................................................................................... 188 Colophon..................................................................................................................... 197 3 Preface XML documents contain regular but flexible structures. Developers can use those structures as a framework on which to build powerful transformative and reporting applications, as well as to establish connections between different parts of documents. XPath and XPointer are two W3C-created technologies that make these structures accessible to applications. XPath is used for locating XML content within an XML document; XPointer is the standard for addressing such content, once located. The two standards are not typically used in isolation but in support of two critical extensions to the core of XML: Extensible Stylesheet Language Transformations (XSLT) and XLink, respectively. They are also finding wide use in other applications that need to reference parts of documents. These two closely related technologies provide the underpinning of an enormous amount of XML processing. Who Should Read This Book? Presumably, if you're browsing a book like this, you already know the rudiments of XML itself. You may have experimented with XSLT but, if so, haven't completely mastered it. (You can't do much in XSLT without first becoming comfortable with at least the basics of XPath.) Similarly, you may have experimented with XLinks; in this case, you've probably focused on linking to entire documents other than the one containing the link. XPointer will be your tool of choice for linking to portions of documents — external to or within the document where the XLink reference is made. As support for XPath is integrated into the Document Object Model (DOM), DOM developers may also find XPath a convenient alternative to walking through document trees. Finally, developers interested in hypertext and other applications where references may have to cross node boundaries will find a thorough explanation of XPointer, the leading technology for creating those references. You need not be an XML document author or developer to read this book. The XPath standard is fairly mature, and therefore is already incorporated in a number of high-level tools. XPointer, by contrast, is not yet a final standard; for this reason, the use of XPointers will probably be limited to experimental purposes in the short term. Regardless of whether you're coming at the subject as primarily a document author or designer, or as a developer, XPath and XPointer can be revisited as often as you need it: for reference or as a refresher. Who Should Not Read This Book? If you don't yet understand XML (including XML