Reputation: 5612
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]]
Upvotes: 3
Views: 368
Reputation: 41569
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.
Upvotes: 2