Using XPaths
-
Names instead of numbers
The simplest typical use of XPath is for establishing structural references which use element names rather than only numbers:
//slides/slide[5]/title
, for example, would refer to the title element of this slide in the orginal XML version. It's more readable, and it's likely to be more stable as well.
-
Great for needles in haystacks
XPath provides some astounding powers for locating information within a document precisely. XSLT gurus regularly identify new possibilities for matching document patterns. Using element names and positions is only the start, as XPath includes functions for finding exactly what you need. (Without the full XSLT context for things like variables, you do lose some functionality.
-
Character issues
XPath notation uses some characters which don't work well in XML, like <. It also uses charcters like [ and ], which need to be URL-encoded: %5B and %5D. A lot of the Unicode characters which can be used in XML aren't supported by URIs, and must be escaped using UTF-8 values. Finally, XPointer itself uses parentheses and circumflexes, and these must be escaped: ^^ for ^, ^( for (, and ^) for ).
-
Wrapping
XPaths (and all XPointers except bare names and child sequences) need to be wrapped in
xpointer()
, like xpointer(//slides/slide%5B5%5D/title)
.
Previous Page <
TOC
> Next Page