VBA读取XML仅适用于本地XML文件

时间:2013-04-09 14:27:40

标签: xml vba

我正在运行以下代码

    Sub test()
        'XML = "C:\R_20130408_1.xml" 'This is local, and works fine
        XML = "http://www.treasurydirect.gov/xml/R_20130408_1.xml" 'This get nothing for "point"
        Dim objXML As DOMDocument
        Dim point As IXMLDOMNode
        Set objXML = New DOMDocument
        With objXML
            .Load XML
            Set point = .SelectSingleNode("//AuctionAnnouncement/CUSIP")
            Sheets(1).Cells(2, 2) = point.Text
        End With

    End Sub

正如你所看到的,如果我从网上下载这个XML,我可以使它工作,否则,objXML仍会加载,但是点不会是什么。

有人会对此提出一些想法吗?

非常感谢! 籍

1 个答案:

答案 0 :(得分:2)

本地XML文件和远程文件之间的XML标头/布局是否可能不同?通过将XPath更改为此字符串,我能够使HTTP版本正常工作:"*/AuctionAnnouncement/CUSIP"