I have an XML ResponseXML object. I'd like to loop throught all nodes called "XYZ". How do I do this?
2 Answers
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
1 Comment
barrowc
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 msdn.microsoft.com/en-us/library/ms757837%28VS.85%29.aspx and blogs.msdn.com/b/xmlteam/archive/2006/10/23/…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