Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parsing XML in VBA

Tags:

xml

vba

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

like image 847
victor Avatar asked Nov 26 '25 06:11

victor


1 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

like image 182
ArBR Avatar answered Nov 27 '25 22:11

ArBR



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!