Till now what all I understand is
::child
looks for immediate child notes of the current node::following
looks for immediate child and sub child and so on of the current node.::descendant
then?Can anyone help me understand with simple example?
The descendant axis indicates all of the children of the context node, and all of their children, and so forth. Attribute and namespace nodes are not included - the parent of an attribute node is an element node, but attribute nodes are not the children of their parents.
following-sibling gets you only the children of the same parent as the current node; following gets all those plus their descendents.
The preceding axis selects all nodes that come before the current node in the document, except ancestor, attribute nodes, and namespace nodes.
child::
will select the immediate descendants of the context node, but does not go any deeper, like descendant::
does.following::
will select all of the nodes that come after the context node and their descendant's, but that does not include the context node's descendants.descendant::
will select all of the nodes along the child::
axis, as well as their children, and their children's children, etc..Sometimes, a picture is worth a thousand words:
Image source, see Figure 3.5
It might be helpful to play with an XPath visualization tool, in order to evaluate your XPath expressions against some sample XML and see what is, and what is not, selected.
For example: http://chris.photobooks.com/xml
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With