Issue with DOM object, code does not loop through DOMElements



I'm trying a simple task to access the USD rate on http://ift.tt/1hdt40r


The issue is that my code does not want to loop through the DOMElements, I have no idea what may be wrong... I have access to another piece of code which is almost identical but uses the XML 3.0 reference library instead and MSXML2.DOMDocument instead and it works perfectly. What could be wrong?


It seems that my selection or DOMDocument is empty...(!), but I'm not sure


My code



Private Sub run() ' run the whole operation

Dim http_req As http_req: Set http_req = New http_req
Dim xDom As MSXML2.DOMDocument60
Set xDom = New MSXML2.DOMDocument60

Dim url As String: url = "http://ift.tt/1hdt40r"
xDom.Load "http://ift.tt/1hdt40r"

Do Until xDom.ReadyState = READYSTATE_COMPLETE
DoEvents
Loop

Call find_ClassElement(xDom)

End Sub

Private Sub find_ClassElement(xDom As MSXML2.DOMDocument60)

Dim ticker As String
Dim xDom_element As MSXML2.IXMLDOMElement
Dim xDom_selection As MSXML2.IXMLDOMSelection

Set xDom_selection = xDom.getElementsByTagName("Cube")

For Each xDom_element In xDom_selection ' <<- The for Each loop never gets executed(!)
On Error Resume Next
ticker = xDom_element.Attributes(0).text
On Error GoTo 0

If ticker = "USD" Then
Debug.Print xDom_element.Attributes(1).text
End If
Next xDom_element
End Sub

No comments:

Post a Comment