How to parse XML using vba

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

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



        
8条回答
  •  抹茶落季
    2020-11-22 09:09

    You can use a XPath Query:

    Dim objDom As Object        '// DOMDocument
    Dim xmlStr As String, _
        xPath As String
    
    xmlStr = _
        " " & _
        "    24.365 " & _
        "    78.63 " & _
        ""
    
    Set objDom = CreateObject("Msxml2.DOMDocument.3.0")     '// Using MSXML 3.0
    
    '/* Load XML */
    objDom.LoadXML xmlStr
    
    '/*
    ' * XPath Query
    ' */        
    
    '/* Get X */
    xPath = "/PointN/X"
    Debug.Print objDom.SelectSingleNode(xPath).text
    
    '/* Get Y */
    xPath = "/PointN/Y"
    Debug.Print objDom.SelectSingleNode(xPath).text
    

提交回复
热议问题