Golang Tutorials - Learn Go Programming with Easy Step-by-Step Guides

Explore comprehensive Golang tutorials for beginners and advanced programmers. Learn Go programming with easy-to-follow, step-by-step guides, examples, and practical tips to master Go language quickly.

Xpath Axes in XML

Xpath Axes in XML

XPath Axes in XML


What are XPath Axes?

  • XPath Axes define the node-set relative to the current node in an XML document.

  • They let you navigate around nodes beyond just children or descendants.

  • Useful to select parents, siblings, ancestors, following nodes, etc.


Common XPath Axes

Axis NameDescriptionExample XPath Expression
childSelects children of the current node (default axis)child::book or simply book
parentSelects the parent of the current nodeparent::bookstore
ancestorSelects all ancestors (parent, grandparent, etc.)ancestor::bookstore
descendantSelects all descendants (children, grandchildren, etc.)descendant::title
following-siblingSelects siblings after the current nodefollowing-sibling::book
preceding-siblingSelects siblings before the current nodepreceding-sibling::book
followingSelects everything in the document after the current nodefollowing::title
precedingSelects everything in the document before the current nodepreceding::book
selfSelects the current nodeself::node()
descendant-or-selfSelects current node and all descendantsdescendant-or-self::book
ancestor-or-selfSelects current node and all ancestorsancestor-or-self::bookstore

Example XML

<bookstore>  <book id="b1">    <title>Book One</title>    <author>Author A</author>  </book>  <book id="b2">    <title>Book Two</title>    <author>Author B</author>  </book></bookstore>

Example Usage

  • Select the parent of <title> node:

    /bookstore/book/title/parent::book
  • Select all ancestor nodes of <title>:

    /bookstore/book/title/ancestor::bookstore
  • Select following sibling books after the first book:

    /bookstore/book[1]/following-sibling::book
  • Select preceding sibling of the second book:

    /bookstore/book[2]/preceding-sibling::book

Summary

  • XPath axes let you navigate XML nodes in various directions.

  • Useful for complex XML queries beyond simple child or descendant selections.

  • Axes have descriptive names like parent, ancestor, following-sibling, etc.


If you want, I can help you write XPath queries using axes for your XML!

Disclaimer for AI-Generated Content:
The content provided in these tutorials is generated using artificial intelligence and is intended for educational purposes only.
html
docker
php
kubernetes
golang
mysql
postgresql
mariaDB
sql