在 VBA 中解析 XML [英] Parsing XML in VBA

查看:44
本文介绍了在 VBA 中解析 XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 XML ResponseXML 对象.我想遍历所有名为XYZ"的节点.我该怎么做?

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

推荐答案

以下是一些可用于解析XML的函数:

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

有关 MSXML 的详细信息,请参阅 MSDN:http://msdn.microsoft.com/en-us/library/aa468547.aspx

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

这篇关于在 VBA 中解析 XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆