Youre already familiar with the XPath way of thinking of documents; for example, its XPath that defines the seven types of document nodes:
The root node. The very start of the document. This node represents the entire document in XPath.
Element nodes. Represents an element in XPath trees, as bounded by a start and matching end tag, or a single empty element tag.
Attribute nodes. The value of an attribute after entity references have been expanded and surrounding whitespace has been trimmed .
Comment nodes. The text of a comment, not including <!-- and -->.
Namespace nodes. A namespace declaration. In XPath, a namespace node is added to each element for each active namespace, including default ones.
Processing instruction nodes. Includes the text of the processing instruction, which does not include <? and ?>.
Text nodes. PCDATA text. Text nodes are normalized by default in XPath, which is to say that immediately adjacent text nodes are merged.
To specify a node or set of nodes in XPath, you use a location path. A location path , in turn , consists of one or more location steps also called simply steps separated by / or //. If you start the location path with /, the location path is called an absolute location path , because youre specifying the path from the root node; otherwise , the location path is relative , starting from the context node .
Location steps, the building blocks of location paths, are much like the step patterns that make up match patterns, which you saw in Chapter 4. In particular, a location step is made up of an axis , a node test , and zero or more predicates , as follows : axis :: nodetest [ predicate ] . For example, in the expression ancestor :: NAME [position() > 100], ancestor is the name of the axis, NAME is the node test and [position() > 100] is the predicate. (The predicate itself holds a complete XPath expressionusually an expression that returns a Boolean value.) You can create location paths with one or more location steps, such as /descendant::PLANET/child::NAME , which selects all the <NAME> elements that have a <PLANET> parent.
XPath steps look like the step patterns you saw in Chapter 4 because the general form is the same axis :: nodetest [ predicate ] but theres a lot more to cover here. For example, there are thirteen axes now, not just two.