I felt the previous post was a bit sloppy, so I re-did the routine using the responsexml.
Public Sub getNOAA_XML()
Dim xmlhttp As Object
Dim strURL As String
Dim n As Integer
Dim times As Object
Dim temps As Object
Dim arrMyData()
strURL = "http://forecast.weather.gov/MapClick.php?lat=38.89500&lon=-77.03730&FcstType=digitalDWML"
Set xmlhttp = CreateObject("microsoft.xmlhttp")
With xmlhttp
.Open "get", strURL, False
.send
With .responsexml
Set times = .getElementsByTagName("start-valid-time")
Set temps = .getElementsByTagName("temperature")(0).ChildNodes
End With
End With
If times.Length = temps.Length Then
ReDim arrMyData(times.Length, 1 To 2)
For n = 0 To times.Length - 1
arrMyData(n, 1) = times(n).Text
arrMyData(n, 2) = temps(n).Text
Next n
ActiveSheet.Range("a1").Resize(UBound(arrMyData, 1), 2) = arrMyData
Else
MsgBox "error"
End If
Set xmlhttp = Nothing
Set times = Nothing
Set temps = Nothing
End Sub
Any feedback on parsing XML would be greatly appreciated as I'd like to learn the subtleties of it. I'm coming across more and more sties that offer XML. From the little I've used it, it's very efficient, as compared to scraping a traditional HTML page.
Bookmarks