Chapter 9. XPath
Just what is XPath? Briefly stated, XPath is to XML what an SQL SELECT is to a relational database. This might at first sound like an oversimplification, but it is essentially true. XPath can be used to locate and navigate t...
9.1. Location Paths
For all its power and flexibility, the location path is probably the easiest type of XPath to start with. Using the XML document in Listing 9-1 as a starting point, let's say that we want to get the root node. This can be acc...
9.2. Context Node
A variation on the previous discussion, //*, is the single period (.), which refers to the context node. Most often used in XSLT to refer to the value of the currently matched node, it works equally well for all node types.
...
9.3. Parent Nodes
Sometimes it is necessary to obtain the parent node(s) of a particular node or node set. This is accomplished by using a double period (..). The following examples show how it can be used to obtain the parent of the series elemen...
9.4. Attribute Nodes
Attribute nodes are handled in a slightly different manner than the nodes that we have dealt with thus far. To specify an attribute node, prefix it with an "at" sign (@). This distinguishes attribute nodes from eleme...
9.5. Predicates
Predicates are the equivalent to an SQL WHERE clause, basically a way to limit the node set returned by XPath. The basic format is as follows:
XPath[condition]
Although this isn't very difficult, most mistakes are made in the con...
9.6. XPath Functions
In addition to what we have seen so far, XPath provides functions that either operate on or return one of the following four data types:
BooleanNumericNode setString
9.6.1. Boolean Functions
XPath has four Boolean functio...
9.7. XPath Expressions
In addition to material already covered, XPath provides some basic mathematical processing. However, it is important to remember that all numbers in XPath are floating-point double precision. In addition, there are special r...
9.8. XPath Unions
Going back to my original comparison that XPath is to XML what an SQL SELECT is to a relational database, there is yet another similarity: unions. In XPath, unions return all nodes in both node sets. This can be quite useful when...
9.9. Axis
Although it's not usually associated with evil (although cursing is a different story), an axis is a node set starting at a particular node that is based on the relationship between the nodes in an XML document. The basic format for usin...
9.10. Summary
The material presented in this chapter completely covers the basic parts of XPath: the various types of paths, context nodes, functions, and axes. As comprehensive as the walkthrough was, it is important to remember that XPath by i...
С 2009 года мы стали переводить структура сайта на различные языки. Сайт теперь будет содержать книги не только на английском языке, но также и на других европейских языках, в том числе и на Русском языке.