Vadiraj Katti
Vadiraj Katti

Reputation: 109

Fetching the value of a child tag in XML when the Xpath is repeating using VBA

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.

Upvotes: 0

Views: 92

Answers (1)

QHarr
QHarr

Reputation: 84465

Answer by @Andersson

root1/rrr/aaa/bbb

Upvotes: 0

Related Questions