在 VBA 中解析 XML
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4550212/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Parsing XML in VBA
提问by victor
I have an XML ResponseXMLobject. I'd like to loop throught all nodes called "XYZ". How do I do this?
我有一个 XMLResponseXML对象。我想遍历所有名为“XYZ”的节点。我该怎么做呢?
回答by ArBR
Here are some functions you can use for parsingyour XML:
下面是一些你可以使用函数解析您的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
有关 MSXML 的更多信息,请参阅 MSDN:http: //msdn.microsoft.com/en-us/library/aa468547.aspx
回答by Dr. belisarius
You may find useful to be able to parse an XML object in VBA.
您可能会发现能够在 VBA 中解析 XML 对象很有用。
See this question: How to parse XML using vba
看到这个问题:How to parse XML using vba
HTH!
哼!
Specifically This Answercovers your problem
特别是这个答案涵盖了你的问题

