How to parse XML using vba

前端 未结 8 1220
不思量自难忘°
不思量自难忘° 2020-11-22 08:46

I work in VBA, and want to parse a string eg



        
8条回答
  •  半阙折子戏
    2020-11-22 09:28

    Thanks for the pointers.

    I don't know, whether this is the best approach to the problem or not, but here is how I got it to work. I referenced the Microsoft XML, v2.6 dll in my VBA, and then the following code snippet, gives me the required values

    Dim objXML As MSXML2.DOMDocument
    
    Set objXML = New MSXML2.DOMDocument
    
    If Not objXML.loadXML(strXML) Then  'strXML is the string with XML'
        Err.Raise objXML.parseError.ErrorCode, , objXML.parseError.reason
    End If
     
    Dim point As IXMLDOMNode
    Set point = objXML.firstChild
    
    Debug.Print point.selectSingleNode("X").Text
    Debug.Print point.selectSingleNode("Y").Text
    

提交回复
热议问题