3

I have an XML ResponseXML object. I'd like to loop throught all nodes called "XYZ". How do I do this?

Cody Gray
  • 230,875
  • 49
  • 477
  • 553
victor
  • 45
  • 1
  • 2
  • 4
  • possible duplicate of [How to parse XML in VBA](http://stackoverflow.com/questions/11305/how-to-parse-xml-in-vba) – Cody Gray Dec 29 '10 at 01:20

2 Answers2

12

Here are some functions you can use for parsing your XML:

Private xml As MSXML.DOMDocument

Private Sub loadXMLFile(xmlFile)    
    Set xml = New DOMDocument
    xml.async = False
    xml.Load (xmlFile) 
End Sub

Private Sub loadXMLString(xmlString)    
    Set xml = New DOMDocument
    xml.LoadXml (xmlString) 
End Sub

Public Function getNodeValue(xpath As String) As String    
    getNodeValue = xml.SelectSingleNode(strXPath).Text    
End Function

Public Function getNodes(xpath as string) As IXMLDOMNodeList            
    Set getNodes = xml.SelectNodes(xpath)
End Function

Public Function getNode(xpath as string) As IXMLDOMNode
    Set getNode = xml.SelectSingleNode(xpath)
End Function

See MSDN for more information about MSXML: http://msdn.microsoft.com/en-us/library/aa468547.aspx

ArBR
  • 3,932
  • 2
  • 22
  • 28
  • 5
    Worth remembering that `DOMDocument` is a synonym for `DOMDocument30` (i.e. MXSML v3.0) and that any more recent version has to have the full version specified as in `DOMDocument60` (for MSXML v6.0) - see http://msdn.microsoft.com/en-us/library/ms757837%28VS.85%29.aspx and http://blogs.msdn.com/b/xmlteam/archive/2006/10/23/using-the-right-version-of-msxml-in-internet-explorer.aspx – barrowc Jan 11 '11 at 01:43
1

You may find useful to be able to parse an XML object in VBA.

See this question: How to parse XML using vba

HTH!

Specifically This Answer covers your problem

Community
  • 1
  • 1
Dr. belisarius
  • 59,792
  • 15
  • 113
  • 189