XML is supposed to be easy to parse, right?

Apparently not if you are using PHP.

Seeing that PHP is a web language, it only makes sense that it should have some functions for parsing XML documents.  Well, as it turns out, the closest thing that it has is XMLReader.  It sounds good, right?  Too bad there is little-to-no documentation on it because it is so new.  Furthermore, it was unnecessarily complicated for my purposes.  I just needed it to read an XML feed from Weather.com.  After a little bit of experimentation, I was able to to get it to do some stuff.  However, it just wasn’t doing what I needed it to do.  So, I ended up writing my own implementation for an XML reader that was specific to the Weather.com feed.  It grabs the current conditions and the forecast and stores it into a neat little array that is formatted into a nice looking table on the main page (I’ll try to get a screenshot up later).  I ended up using icons from the Weather widget for an awesome widget program called Screenlets.  So, now, the weather box is working fine.  That makes me happier.  Although I nearly drove myself insane trying to get the XML parser to work.  I ended up just using a bunch of explode() calls, although I probably could have done a better job with Regex.  Also, I was able to get the email to load asynchronously, so the load time of the page is much faster now.

What PHP really needs is a function that will take XML data and turn it into a multi-branched array.  It shouldn’t be that hard to do.  Maybe I’ll write one myself one day.

0 Responses to “XML is supposed to be easy to parse, right?”

Comments are currently closed.