So in the aftermath of yesterday, Valette asked for a way to display the current weather in Fairbanks on her page. Turns out that she found an XML feed for it from NOAA, which was great, but it was in XML which she doesn't know at all. (She being someone with a life and not living and breathing this sort of crap.)
Thing is that while really powerful, PHP4's XML handling kind of sucks for quick and dirty XML parsing. (i haven't tried to screw around with PHP5 yet. That's one of the things i need to configure the box in the garage to do and there's a ton of other things tha need to be set up first)
Still, if you have a file full of simple, attribute free XML like the NOAA feed, the SAX model seems like too much work and the XML_DOM model seems like complete overkill. The sample code on the XML works great, but it returns an array of hashes. Nice, but not really the easiest thing in the world to navigate and extract data.
So i built a really simple php xml to hash function. It ignores attributes but converts a standard xml list to php hash library. i've even got a quicky little module that shows off how it works. As a bonus, this is also really useful for work. (yeah, it's ugly code, but it works. i'll probably add some additional code to automatically build out arrays of values.)
See? You help someone else and you make your own life easier.
Save This Page
