I’m trying to open/load an XML file specified in an Excel worksheet in the range B2. Then, search through a list of XML attributes for name=FUNCTIONAL_ITEM and get all the attribute values after ">.
In the following example, i’d like to extract out the value 8, 9 and 10.
<Attribute name="BIN" dataType="String" unit="" multiplier="" tag="LINE,MRPM">1</Attribute>
<Attribute name="FUNCTIONAL_ITEM" dataType="Double" unit="" multiplier="" tag="LINE,LINE DB">8</Attribute>
<Attribute name="FUNCTIONAL_ITEM" dataType="Double" unit="" multiplier="" tag="LINE,LINE DB">9</Attribute>
<Attribute name="FUNCTIONAL_ITEM" dataType="Double" unit="" multiplier="" tag="LINE,LINE DB">10</Attribute>
Could someone please point me in the right direction for implementing this.
What you need to use is XPath. Assuming that you have your XML document in a
DomDocument60object which we’ll calldand you have declared anIXMLDOMNodeListvariable calledithen use this:Set i = d.selectNodes("//Attribute[@name='FUNCTIONAL ITEM']")You can then iterate through the nodes in
iand extract thetextproperty from each node.Here’s a fairly minimal program to demonstrate (you need to add a reference to “Microsoft XML, v6.0” via Tools > References if you haven’t done so already):