我正在尝试从 ECB URL 每天下载一组 FX 报价。它似乎使用 DOMDocument 工作,但当我切换到 DOMDocument60 时不起作用。我在下面的代码中包含了这两种方法。我相信我的 XPath 语法是正确的——用“时间”元素识别所有 Cube 节点,以便能够识别时间序列中每一天的报价。
谁能告诉我我做错了什么?
Sub XMLDom60vs30()
Dim oXMLHTTP As Object
Dim sURL As String
Dim XmlMapResponse As String
Dim strXML As String
Dim xDoc As Object
Dim xDoc60 As MSXML2.DOMDocument60
Dim xNodeList As Object
Dim xNodeList60 As MSXML2.IXMLDOMNodeList
' This URL access daily FX history from an ECB website.
sURL = "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist.xml?affd3fe4c0ac916ce2e9d1ccfea2327c"
Set oXMLHTTP = CreateObject("MSXML2.ServerXMLHTTP")
Set xDoc = CreateObject("MSXML2.DOMDocument")
Set xDoc60 = New MSXML2.DOMDocument60
oXMLHTTP.Open "GET", sURL, False
oXMLHTTP.send
XmlMapResponse = oXMLHTTP.responseText
strXML = XmlMapResponse
With xDoc
.async = False
.validateOnParse = False
.LoadXML (strXML)
End With
With xDoc60
.async = False
.validateOnParse = False
.LoadXML (strXML)
End With
Set xNodeList = xDoc.SelectNodes("//Cube[@time]")
Set xNodeList60 = xDoc60.SelectNodes("//Cube[@time]")
Debug.Print "List Length: xNodes = " & xNodeList.Length & ", XNodes60 = " & xNodeList60.Length & ", finished at " & Format(Now(), "hh:mm:ss")
End Sub