I have an XML of format
...
<parent>
<child name='a' />
</parent>
<parent>
<child name='b' />
<child name='c' />
<child name='d' />
</parent>
...
Now, i'm using XPath expression //parent/child[@name] to fetch the child node names. But I'm getting everything in a flat list, in this instance its a list of 4 nodes.
Is there a way (xpath expression) to fetch the nodes grouped by the parent as in [[a],[b,c,d]]
Sounds like you need two loops, one on //parent, and then a sub query for child[@anme]. That should allow you to work with the child names in their groups. XPath will otherwise just return all matching nodes, irrespective of ancestry.
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