Xpath and Xpointer: Locating Content in XML Documents

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Referring to specific information inside an XML document is a little like finding a needle in a haystack: how do you differentiate the information you need from everything else? XPath and XPointer are two closely related languages that play a key role in XML processing by allowing developers to find these needles and manipulate embedded information. XPath describes a route for finding specific items by defining a path through the hierarchy of an XML document, abstracting only the information that's relevant for identifying the data. XPointer extends XPath to identify more complex parts of documents. Written for XML and XSLT developers and anyone else who needs to address information in XML documents, the book assumes a working knowledge of XML and XSLT. By the time you've finished the book, you'll know how to construct a full XPointer (one that uses an XPath location path to address document content) and completely understand both the XPath and XPointer features it uses.

Author(s): John Simpson
Edition: 1
Publisher: Oreily
Year: 2002

Language: English
Pages: 197

Table of Content......Page 2
Preface......Page 3
Who Should Not Read This Book?......Page 4
Conventions Used in This Book......Page 5
Comments and Questions......Page 6
Acknowledgments......Page 7
1.1 Why XPath and XPointer?......Page 8
1.2.1 DSSSL......Page 9
1.2.2 XSL......Page 10
1.2.3 TEI......Page 11
1.3 XPath, XPointer, and Other XML-Related Specs......Page 12
Figure 1-1. Interdependencies among XML-related standards......Page 13
1.3.1 Specs Dependent on XPath and XPointer......Page 14
1.4 XPath and XPointer Versus XQuery......Page 15
Figure 2-1. Above XML document represented as a tree of nodes......Page 17
2.2 XPath Expressions......Page 18
2.2.1 Location Steps and Location Paths......Page 20
2.2.2.2 Delimiters......Page 21
2.2.2.3 Combining tokens and delimiters into complete expressions......Page 23
2.3.1 Strings......Page 24
2.3.2 Numeric Values......Page 25
2.4.1.1 Node names......Page 27
2.4.1.2 Document order......Page 28
2.4.2 Node-Sets......Page 29
2.4.3.2 Element nodes......Page 30
Figure 2-3. The same XML document with whitespace......Page 32
2.4.3.3 Attribute nodes......Page 33
2.4.3.4 PI nodes......Page 35
2.4.3.7 Namespace nodes......Page 36
2.5 Node-Set Context......Page 38
Table?2-1. String-values, by node type......Page 40
2.6.1 String-Value of a Node-Set......Page 42
3.1.2 Points of Similarity, Points of Difference......Page 43
Figure 3-1. Filtering content via successive steps in a location path......Page 45
3.2.2 Absolute Versus Relative Location Paths......Page 46
3.3 Location Steps......Page 47
Figure 3-2. Narrowing the field of vision: "seeing" just boats with sails in a particular direction......Page 49
Table?3-1. Location step node tests......Page 50
Table?3-2. Location step axes......Page 51
3.3.3.1 Defaults and shortcuts......Page 52
Table?3-3. Valid axis/context node combinations......Page 54
3.3.3.3 Axes and efficiency......Page 55
Table?3-4. Boolean operators in XPath predicates......Page 56
3.3.4.2 Compound predicates......Page 58
3.3.4.3 Predicates with a single value and no operator......Page 60
3.3.4.5 "Stacked" predicates......Page 61
3.4 Compound Location Paths Revisited......Page 63
4.1 Introduction to Functions......Page 64
4.1.2 Functions Within Functions......Page 65
4.2 XPath Function Types......Page 66
4.2.1 Node-Set Functions......Page 67
4.2.1.1 last()......Page 68
4.2.1.2 position()......Page 69
4.2.1.3 count(nodeset)......Page 70
4.2.1.4 id(anytype)......Page 71
4.2.1.6 local-name(nodeset?)......Page 72
4.2.1.7 namespace-uri(nodeset?)......Page 73
4.2.1.8 name(nodeset?)......Page 74
4.2.2 String Functions......Page 75
4.2.2.1 string(anytype?)......Page 77
4.2.2.2 concat(string1, string2, ...)......Page 79
4.2.2.4 contains(string1, string2)......Page 80
4.2.2.5 substring(string, number1, number2?)......Page 81
4.2.2.8 normalize-space(string?)......Page 82
4.2.2.9 translate(string1, string2, string3)......Page 83
4.2.3.1 boolean(anytype)......Page 85
4.2.3.2 not(boolean)......Page 87
4.2.3.4 lang(string)......Page 88
4.2.4.1 number(anytype?)......Page 89
4.2.4.2 sum(nodeset)......Page 90
4.2.4.4 round(number)......Page 91
4.3.1 div......Page 92
4.3.2 mod......Page 93
5.1 XPath Visualiser: Some Background......Page 95
Figure 5-2. A document loaded into XPath Visualiser......Page 96
5.2 Sample XML Document......Page 97
Figure 5-3. Sample astrological document loaded into XPath Visualiser......Page 98
Figure 5-4. "Locating" the root node......Page 99
Figure 5-6. Locating all comments......Page 100
Figure 5-7. Locating a PI......Page 101
Figure 5-9. Locating all elements, comments, PIs, and text nodes......Page 102
Figure 5-10. Locating attribute nodes......Page 103
Figure 5-11. Locating namespace nodes......Page 104
Figure 5-13. Locating the parents of any part elements......Page 105
Figure 5-14. Using the parent:: axis to locate attributes of a comment's parent element......Page 106
Figure 5-16. Locating elements along the following:: axis......Page 107
Figure 5-17. Locating an element's ancestors......Page 108
Figure 5-19. Trimming a node-set using a predicate......Page 109
Figure 5-20. Selecting all elements with an attribute whose value does not meet a condition......Page 110
Figure 5-22. Locating nodes based on their positions......Page 111
Figure 5-23. Node position on a reverse-direction axis......Page 112
5.3.4 Functions......Page 113
Figure 5-25. Locating href pseudoattributes and xlink:href attributes with a single location path......Page 114
Figure 5-27. Using XPath string functions......Page 115
5.3.5 Sublimely Ridiculous......Page 116
Figure 5-29. Locating the sign elements with "plural body parts"......Page 117
Figure 5-31. Locating the true name of each sign with "plural body parts"......Page 118
Figure 5-32. Locating signs with more than one ruling planet......Page 119
Figure 5-33. Locating the image file for the symbol of each sign with more than one ruling planet......Page 120
Figure 5-34. Locating all Unicode and image-file representations of the symbols for all signs with more than one ruling planet......Page 121
6.1.1 Simplify Manipulation of XML Schema-Typed Content......Page 122
6.1.5 Improve Interoperability......Page 124
6.1.8 Enable Improved Processor Efficiency......Page 125
Table?6-1. XPath 2.0 requirements, by general goal......Page 126
6.2.1.2 Provide common core syntax and semantics for XSLT and XML Query (1.2)......Page 127
6.2.1.3 Support explicit "for any" and "for all" Boolean operations (1.3)......Page 129
6.2.1.5 Loosen restrictions on location steps (2.1)......Page 130
6.2.1.7 Define consistent implicit semantics for collection-valued subexpressions (2.3)......Page 131
6.2.1.8 Support string matching with regular expressions (3)......Page 132
6.2.1.10 Allow scientific notation for numbers (4.2)......Page 133
6.2.1.13 Define the behavior of operators for null arguments (4.6)......Page 134
6.2.2.2 Provide intersection and difference functions (1.6)......Page 135
6.2.2.4 Simplify string replacement (2.4.1)......Page 136
6.2.2.6 Simplify string case conversions (2.4.3)......Page 137
6.2.2.9 Select elements/attributes based on an explicit XML Schema type (5.1)......Page 138
6.2.2.12 Support lookups based on XML Schema unique constraints and keys (5.4)......Page 139
7.1 XPointer and Media types......Page 141
7.2.1 Resource......Page 143
7.2.5 Point......Page 144
7.2.6 Range......Page 145
7.3 The Framework......Page 146
7.4.3 Subresource Errors......Page 147
7.5.1 Characters Significant to XPointer Itself......Page 148
7.5.3 Characters in XML Documents......Page 149
7.5.4.1 Progressive escaping: a (perverse) example......Page 150
8.1 Shorthand Pointers......Page 153
8.2.1 The Scheme......Page 154
8.2.4 Contents of the element() Scheme......Page 155
8.2.6 Contents of the xpointer() Scheme......Page 158
8.2.7 Custom Schemes......Page 159
8.2.8.2 Declaring and using namespaces......Page 161
8.2.8.3 Mixing it up......Page 162
8.3 Using XPointers in a URI......Page 163
Figure 9-2. Hypothetical web document (with selection)......Page 165
9.2.1 Points......Page 166
9.2.1.1 Node points versus character points......Page 168
Table?9-1. Axes and points......Page 169
9.2.2 Ranges......Page 170
9.2.2.2 Range syntax......Page 171
9.2.2.3 Ranges as "nodes"......Page 172
Table?9-2. Covering ranges......Page 173
9.3 XPointer Extensions to Document Order......Page 174
Table?9-4. Document order and location types......Page 176
9.3.1 XPointer Document Order Extensions: Examples......Page 177
9.4 XPointer Functions......Page 178
9.4.1 start-point(locset)......Page 179
9.4.2 end-point(locset)......Page 180
9.4.3 range-to(locset)......Page 181
9.4.4 string-range(locset, string, number1?, number2?)......Page 182
Table?9-7. range-inside() behavior, by location type......Page 183
9.4.7 here()......Page 184
9.4.8 origin()......Page 185
Table?A-1. Additional functions provided by XSLT 1.0......Page 187
A.2.1 EXSLT Functions Module......Page 188
Table?A-4. EXSLT Dates-and-times module functions......Page 189
A.2.3 EXSLT Dynamic Module......Page 191
Table?A-6. EXSLT Common module element......Page 192
Table?A-8. EXSLT Math module functions......Page 193
Table?A-10. EXSLT Sets module functions......Page 194
Table?A-11. EXSLT Strings module functions......Page 195
Colophon......Page 197