« Reader Feedback: Experiences With Django
» Reader Feedback: Web Application Performance

Chris' Brain

Reader Feedback: Working with XML In PHP

08.27.08 | 1 Comment

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:

  1. Use eXist to give me a list of documents that contain the info I am looking for
  2. Load those documents into SimpleXML
  3. 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: ,

1 Comment

have your say

Add your comment below, or trackback from your own site. Subscribe to these comments.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

:

:


« Reader Feedback: Experiences With Django
» Reader Feedback: Web Application Performance