Google XML Weather Feed with Classic ASP

This took me a few days to get working and it drives me crazy because of how simple it is. My problem is that I tried to do it in Javascript first and my Javascript skills aren’t up to my ASP skills.

It is actually quite simple and here is the code.


set xmlHTTP = server.createobject("Microsoft.XMLHTTP") "Get", ",pa", false
Set xml = xmlHTTP.ResponseXml
city = xml.documentElement.childNodes(0).firstChild.firstChild.attributes(0).nodeValue

currenttemp = xml.documentElement.childNodes(0).firstChild.nextSibling.childNodes(1).attributes(0).nodeValue
conditionstext = xml.documentElement.childNodes(0).firstChild.nextSibling.childNodes(0).attributes(0).nodeValue
conditionsicon = xml.documentElement.childNodes(0).childNodes(2).childNodes(3).attributes(0).Value


Then you can just response.write the values where you need them.

Bringing the object back was pretty easy, but traversing the DOM to get the information that I was looking for was a real pain. A combination of Firefox and Firebug made selecting what I needed a lot easier.

You will also notice that I have ‘philadephia, pa’ harcoded into the URL, but where this is being used, I use an IP locator to get the IP address of the user, convert that to a city and state and put that value into the URL, so that users can get their own weather and not mine.

Also ‘conditionsicon’ brings back a relative URL to an icon image for the current conditions. If anyone has a list of all possible conditions that would be amazingly helpful.