Consider the following very simplified example.
<n></n> <k></k> <m></m> <k></k>
How can I search for a first k
sibling after m
node? Basically, find some node and then continue searching from that node.
To traverse to the next sibling, we have to use the following-sibling concept in xpath. This will allow us to traverse to the next sibling from the present sibling of the same parent. Let us try to move from the first child<h1> of parent <div> to the second <h2> as in the above image.
Sibling nodes are nodes on the same hierarchical level under the same parent node. Nodes higher than a given node in the same lineage are ancestors and those below it are descendants.
How can I search for a first
k
sibling afterm
node? Basically, find some node and then continue searching from that node.
Assuming that we have the following well-formed XML document:
<t> <n></n> <k></k> <m></m> <k></k> </t>
then the following XPath expression:
/*/m[1]/following-sibling::k[1]
selects the first k
following-sibling of the first m
child of the top element of the XML document.
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