3

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]]

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Yeah, Just figured that out... implemented it... n its working fine. THanks for the quick response.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.