XPath learning: Axis (4) -- ancestor

Source: Internet
Author: User

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.

 

The ancestor axis contains the ancestor nodes of the upper and lower nodes, which are composed of the parent nodes of the context nodes and the parent nodes of the parent nodes, therefore, the ancestor axis always contains the root node, unless the context node is the root node itself.

/AAA/BBB/DDD/CCC/EEE/ancestor: * select all nodes in an absolute path.

<AAA>
<BBB>
<DDD>
<CCC>
<DDD/>
<EEE/>
</CCC>
</DDD>
</BBB>
<CCC>
<DDD>
<EEE>
<DDD>
<FFF/>
</DDD>
</EEE>
</DDD>
</CCC>
</AAA>

// FFF/ancestor: * select all ancestor nodes of the FFF element.

<AAA>
<BBB>
<DDD>
<CCC>
<DDD/>
<EEE/>
</CCC>
</DDD>
</BBB>
<CCC>
<DDD>
<EEE>
<DDD>
<FFF/>
</DDD>
</EEE>
</DDD>
</CCC>
</AAA>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.