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 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.
The attribute axis Selects all the attributes of the current node. The result is the attribute instead of the node. All the axes are the selected nodes.
/AAA/BBB/attribute: * select all attributes of the/AAA/BBB node.
<AAA>
<BBB aaa = "111" bbb = "222">
<CCC/>
<CCC xxx = "555" yyy = "666" zzz = "777"/>
</BBB>
& Lt; BBB aaa = "999" & gt;
<CCC xxx = "qq"/>
<DDD xxx = "ww"/>
<EEE xxx = "oo"/>
</BBB>
<BBB>
<DDD xxx = "oo"/>
</BBB>
</AAA>
// CCC/attribute: * select all attributes of all CCC nodes
<AAA>
<BBB aaa = "111" bbb = "222">
<CCC/>
<CCC xxx = "555" yyy = "666" zzz = "777"/>
</BBB>
& Lt; BBB aaa = "999" & gt;
<CCC xxx = "qq"/>
<DDD xxx = "ww"/>
<EEE xxx = "oo"/>
</BBB>
<BBB>
<DDD xxx = "oo"/>
</BBB>
</AAA>