XPath is a language used to search for information in XML documents. XPath can be used to traverse elements and attributes in XML documents.
XPath is the main element of W3C XSLT standards, and XQuery and XPointer are also built on XPath expressions.
We recommend a pretty good site: there are good examples in the http://www.zvon.org/xxl/XPathTutorial/General_chi/examples.html, the red font in the following example represents the elements (or attributes) obtained using the corresponding syntax ).
The XPath axis (XPath Axes) defines a node set relative to the current node:
1. child Selects all child elements of the current node
2. parent select the parent node of the current node
3. descendant Selects all descendant elements (child, sun, etc.) of the current node)
4. ancestor Selects all the ancestors of the current node (parent, grandfather, etc)
5. descendant-or-self Selects all descendant elements (child, sun, etc.) of the current node and the current node itself.
6. ancestor-or-self Selects all the ancestors of the current node (parent, grandfather, etc.) and the current node itself
7. preceding-sibling: select all peer nodes before the current node
8. following-sibling Selects all peer nodes after the current node
9. preceding Selects all nodes before the start label of the current node in the document.
10. following select all nodes after the end label of the current node in the document
11. Select the current node by self
12. attribute Selects all attributes of the current node.
13. Select All namespace nodes of the current node.
Child is the default axis of Xpath and can be omitted without writing. The following is a simple example:
/Child: AAA is equivalent to/AAA
<AAA>
<BBB/>
<CCC/>
</AAA>
/Child: AAA/child: BBB is equivalent to/AAA/BBB
<AAA>
<BBB/>
<CCC/>
</AAA>
/Child: AAA/BBB is also equivalent to/AAA/BBB
<AAA>
<BBB/>
<CCC/>
</AAA>
The child axis is relatively simple, and is generally ignored and not written.