lion
lion

Reputation: 103

VBA read XML only works for local XML files

I was running the following code

    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

As you can see, if I download this XML from the web, I can get it working, otherwise, objXML will still load, but point will be nothing.

Would anybody offer some thoughts on this?

Many thanks! Ji

Upvotes: 0

Views: 1273

Answers (1)

Fink
Fink

Reputation: 3436

Is it possible the XML headers/layout are different between the local XML file, and the remote file? I was able to get the HTTP version working, by changing the XPath to this string: "*/AuctionAnnouncement/CUSIP"

Upvotes: 2

Related Questions