Duh,
What you're talking about is XPATH - used to query an xml file.
Here's a simple XML file:
<Drawings>
<Drawing>
<Name>Dwg1</Name>
<Path>C:\Temp</Path>
</Drawing>
<Drawing>
<Name>Dwg2</Name>
<Path>C:\Temp</Path>
</Drawing>
<Drawing>
<Name>Dwg3</Name>
<Path>C:\Temp</Path>
</Drawing>
</Drawings>
...and some VBA to manipulate it:
Option Explicit
Private Const CFG_FILE As String = "C:\Temp\Drgs.xml"
Public Sub XmlTest()
Dim pCfgDoc As DOMDocument
Dim pFSO As FileSystemObject
' Spin up the filesystem object...
Set pFSO = New FileSystemObject
' Check if our xml cfg file exists...
If Not pFSO.FileExists(CFG_FILE) Then Exit Sub
' Spin up a new xml document...
Set pCfgDoc = New DOMDocument
' Load in our configuration data...
pCfgDoc.Load CFG_FILE
' Get all the 'Drawing' elements...
Dim pDrgNodes As IXMLDOMNodeList
Dim pDrgNode As IXMLDOMNode
Dim pDrgNameNode As IXMLDOMNode
Dim pDrgPathNode As IXMLDOMNode
Set pDrgNodes = pCfgDoc.selectNodes("/Drawings/Drawing")
' Loop the drawing nodes...
For Each pDrgNode In pDrgNodes
Set pDrgNameNode = pDrgNode.selectSingleNode("Name")
Debug.Print pDrgNameNode.text
Set pDrgPathNode = pDrgNode.selectSingleNode("Path")
Debug.Print pDrgPathNode.text
Next
' Go straight for a particular node...
Dim someSearchVariable As String
Dim pExtraSpecialDrgNode As IXMLDOMNode
someSearchVariable = "Dwg2"
Set pExtraSpecialDrgNode = pCfgDoc.selectSingleNode("/Drawings/Drawing[Name='" & someSearchVariable & "']")
If pExtraSpecialDrgNode Is Nothing Then Exit Sub
Debug.Print vbCr + vbCr + pExtraSpecialDrgNode.text
Set pDrgNameNode = pExtraSpecialDrgNode.selectSingleNode("Name")
Debug.Print pDrgNameNode.text
End Sub
Set a reference in VBA to "Microsoft XML, v3.0" or above.
I strongly suggest you look at the short tutorials for XML and XPATH available at w3c.
Cheers,
Glenn.