Weather Underground XML API

Weather Underground has a nice XML API to get at their data, and I recently used it to create a small weather page for my friend's new HTC Hero. This little page turned into a learning exercise for me on both the Weather Underground API and SimpleXMLElement in PHP.

SimpleXMLElement: What a great way to parse XML! I've been avoiding XML in my code up until now because it's so freaking clunky to implement. But with this I'm eager for the next chance to use XML. I can sum it up in two lines of code (long lines, bear with me):

::CODECOLORER_BLOCK_1::

So you see, I read the XML data into $xml_current_cond, and then I access the data through $xml_current_cont->[XML_TAG_NAMES]. It really couldn't be much simpler.

While I'm no fan of the spaghetti code that you get from writing PHP, I also realize that it doesn't matter. Everyone writes PHP, and SimpleXMLElement is a good example of why they use PHP.

Leave a Reply

Your email address will not be published.