I started working on a nice little personal project in PHP. It has a specific real-world use, and in evaluating the approaches I could take with the design, I decided that it didn’t need a database. Rare for me. I like databases. The only data this application needs to store is general system configuration settings, which I thought would be best stored as a simple XML file. I like XML – much more than databases.
So I began carrying out proof-of-concepts on each of the major parts of the project. I searched on the excellent php.net for the XML functions, and found them. Hmm.
Why is PHP’s XML implementation so crap? How has it managed this long without DOM support? I can see it’s on its way, but how has everyone been managing? Do PHP developers not care about XML?
I’ve settled with parsing my XML file out into an array of arrays (yuk), which is useable but hideous and putrid. I think I’m going to have to design my application in such a way as when DOMXML is widely supported in general PHP installations I’ll be able to easily recode to make use of it. At least there’s an interesting challenge in that.
Seriously, I’m not having a rant, I really want to know this. How do PHP developers deal with XML without a DOM? What do you use? Is there something altogether DOM-tastic out there that I’m missing?
I’ve had no problems with other parts of the project. The bit which I thought would be difficult (POP3 integration) was as easy as pie, if not easier. So praise be. It’s just this damn XML.




Comments
I remember finding the sample scripts I used in O’Reilly’s PHP Cookbook. If you’d like, I can email you a couple of links/snippets.
when i can, i use an xslt stylsheet (say to transform an xml file to xhtml or rss) but obviously for your situation this doesn’t help.
i’d like to see a better way.
What I’ve been playing with is almost exactly what vlad mentioned eg.
php generates xml -> xml is parsed though an xsl stylesheet by php -> returned (valid) xhtml is styled with css
What really gets me is php’s lame rendition of classes, but that’s another story.
As for classes .. PHP classes are great compared with what you get in VBScript.
I also think XML is over used. As a typical example, (although this doesnt apply to Drew, cos it’s perfect for your needs) I have seen developers, pull info out a DB into XML format and then parse the code and display it on the page, now thats an awful lot of work for no added benefit. XML is valuable, for example, when two machines need to talk to each other but otherwise couldn’t.
PHP has the function parse_ini_file(), which I find very useful. This pushes the information into an array, allowing for multi-dimensional arrays when using an ini syntax as follows:
This, for me, its extreamily fast and easy to use. You can even push this to a session variable:
All my projects are created in XML. I have an XML Database or file store. I use XSL for templates. I use PHP's XSL functions for translation before pushing to the browser. I use XUpdate for updating information within the DB. I use XPath to get it back out.
I've never had a problem with it. But then again, I don't use PHP to mess with the XML. The backend and frontends I use don't need me to.
I used to use PHP/MySQL. Wonderful as it is, I found that I would be parsing information, screwing with it, validating it, merging it, and generally passing it from pillar to post before anything really could be done with it.
If you really want to use PHP for XML, try:
http://phpxmlclasses.sourceforge.net/
http://www.carrubbers.org/scripts/php/xpath/
http://www.carrubbers.org/scripts/php/xmldb/
These might help.
Otherwise, look at:
http://xml.apache.org/xindice/
http://exist.sourceforge.net
Happy coding!
Have a look at http://www.phpclasses.net/ - sign up as a member. Their XML section contains a number of useful routines to handle, produce and manipulate XML.
The DOM libraries looks promising, but they aren’t ready from prime time yet (it has been this way for years).
The XSLT libraries aren’t bad but, like the DOM libs, they aren’t installed by default, so often they aren’t available on shared servers...
Sure, there are good libraries that abstract XML parsing, SOAP, XML-RPC and the like (using SAX in the background), both from PEAR and other sources. But I firmly believe this kind of stuff should be available out of the box