Welcome to the 3rd installment of me answering reader feedback questions. Today we deal with a topic that I deal with every day at my day job — working with XML in PHP.
First of all, I do all this in PHP 5. SimpleXML makes it so easy to manipulate XML. For my main work project, I’ve written a PHP application front end that talks to eXist, an open source XML database. Since we deal with XML all day long it was decided that we needed to eat our own dog food and go with an XML database to store the information that the application generates. So a lot of my code does some of the following things:
- Do a call to a xQuery script running on the database that returns info that I’m looking for, usually both comma and pipe-separated data
- Load a specific document into a SimpleXML object and pull out some specific info
- Load a specific document into a SimpleXML object and then use it’s XPath functions to pull some information out.
Those 3 techniques seem to work well for me when dealing with XML data in PHP. If I had to go back and redo some of the earlier code, I’d probably change things a little differently in how I’m using eXist to simulate how some of our other products work:
- Use eXist to give me a list of documents that contain the info I am looking for
- Load those documents into SimpleXML
- Use Xpath to grab the data I needed
But in the interest of Getting Things Done, what I’ve done works pretty good and the code is really not horrible.
Tags: reader feedback, XML


“… works pretty well”?
I haven’t done much with XML databases but I have found SimpleXML to be extremely useful when working with XML data. PHP definitely has that nailed. I even use it for parsing WordProcessingML documents – Microsoft Office 2003’s answer to “XML” documents. It’s absolutely horrible – if you have a block of bold text you’d think there would be some sort of tag surround it, right? No, it’s a sibling tag to the text that marks it as bold. Or italic. Or anything else. It’s a nightmare, but at least it’s navigable once you throw SimpleXML into the mix.