【问题标题】:Parsing XML in VBA在 VBA 中解析 XML
【发布时间】:2011-05-31 19:34:49
【问题描述】:

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

【问题讨论】:

标签: xml vba


【解决方案1】:

以下是一些可用于解析您的 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

【讨论】:

【解决方案2】:

您可能会发现能够在 VBA 中解析 XML 对象很有用。

看到这个问题:How to parse XML using vba

HTH!

特别是This Answer 解决您的问题

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-04-20
    • 1970-01-01
    • 1970-01-01
    • 2012-07-15
    • 2010-09-05
    • 1970-01-01
    • 2019-07-29
    相关资源
    最近更新 更多