Reputation: 503
I have a search screen where you can select different options (items that are child nodes). After hitting search I would like togo through a XML document and retrieve the parent node attribute. For example:
<?xml version="1.0" encoding="UTF-8"?>
<brands>
<BrandA Name="A Brand">
<Color>Black</Color>
<Thickness>1"</Thickness>
<Texture>Smooth</Texture>
</BrandA>
<BrandB Name="B Brand">
<Color>Red</Color>
<Thickness>2"</Thickness>
<Texture>Smooth</Texture>
</BrandB>
<BrandC Name="C Brand">
<Color>Green</Color>
<Thickness>3"</Thickness>
<Texture>Rough</Texture>
</BrandC>
</brands>
If someone is searching from a "Rough" texture how could I get the parent node of BrandC Name?
VBA CODE:
For Each T In objDom.getElementsByTagName("Texture")
MsgBox T.Text 'For testing to see what it returns (all 3 textures).
If ComboBox3.Value = T.Text Then
'For testing: This returns all matching textures that was selected.
MsgBox T.ParentNode.Text
End If
So this returns everything Brand name, color, thickness, texture. I just need the Brand Name IE "C Brand".
Upvotes: 1
Views: 3508
Reputation: 50034
Instead of T.ParentNode.Text
I believe you will want T.ParentNode.Attributes.getNamedItem("Name").Text
Upvotes: 2