0
votes

I have an XPath lets say "/rrr/aaa/Parenttag/Childtag" under a parent . I need to fetch the value present in the Child tag. This Xpath is repeating multiple times in the same Xml document. So I'm using "/rrr/aaa/Parenttag/Childtag" with the '' (asterisk) in the beginning.

The issue I'm facing now is that my Xpath is also a part another parent . As I'm using the "*", the data from is also being fetched. Is there a way to get the data only from and not any other Parents?

I hope my explanation was understandable.

Thanks for any help.

Edit:

I'm unable to upload the actual XML. So here is a snippet of the structure of XML that I have.

Please click link to see an image of how my data is structured

The XPath is /rrr/aaa/bbb. I need the values present in bbb for all the times it is repeating. Im using */rrr/aaa/bbb to as the Xpath using the following code to the data that I want. However, I need the data that is present only under the parent tag . The same tags are repeated under .

Range("A2").Value = "*/rrr/aaa/bbb"

Set nodeXML = xmlDoc.getElementsByTagName(Range("A2").Value)

For i = 0 To nodeXML.Length - 1

    For Each chlnodes In nodeXML(i).ParentNode.ChildNodes
           Next chlnodes

    Range("B" & i + 1).Value = nodeXML(i).Text
Next

Hope this makes more sense.

Thanks.

1
What do you have so far?ashleedawg
Set nodeXML = xmlDoc.getElementsByTagName(Range("A2").Value) For i = 0 To nodeXML.Length - 1 For Each chlnodes In nodeXML(i).ParentNode.ChildNodes Next chlnodes Range("B" & i + 1).Value = nodeXML(i).Text Next I have something likr thisVadiraj Katti
Can you share XML sample for the same along with the current and desired outputAndersson
Andersson, I have made an edit in my question. Can you see if it helps.I need the data under that tag <bbb>, but only for the parent tag <root1> not <root2>Vadiraj Katti
So why you cannot use root1/rrr/aaa/bbb?Andersson

1 Answers

0
votes

Answer by @Andersson

root1/rrr/aaa/bbb