I spent the most of Sunday working on my project, learning oodles more about PHP and battling with various ways of treating XML. The solution I settled with was this.
One thing that PHP (like Perl before it) does really well is reading a writing files, whereas one thing it does fairly badly at the present time (future DOM functions excluded) is XML parsing. This much is known. If I was writing this in Perl I would probably use comma delimited value (CSV) files for storing my data and would have read a line at a time, splitting the string on the commas to form an array. The problem with CSV files is they are not of robust structure, and their really tricky to edit by hand. So why not use XML and treat it as a more structured text file? Why not indeed. So that’s what I’m doing. Screw the XML functions, I’ve decided to write my XML using basic string manipulation. (I like string manipulation almost as much as XML).
The second part of my strategy is to use lots of small XML files rather than getting fancy and building big ones. This makes them easy to write, and if I need to serialize the file into an array, it prevents the array getting to complex, thus being easy on the brain and easy on the eye.
The third part of my plan (and this is why it makes the most sense to stick with XML as a file format) is to transform my data to XHTML using XSLT. PHP’s basic XSLT functionality seems pretty sound, although I did have a hard time getting it working. I ended up having to do a dl('xslt.so'); to get the module to load. Any suggestions why, or how I can load it automatically?
I’m paring my small XML files with small XSLT files, which will hopefully keep the processing overhead down. The really neat aspect of the PHP xslt_process() function is that you can simply pass it the addresses of your XML and XSL files and it performs the transformation without you having to specifically create file pointers for either, which is tidy. I guess it’s also more performant – it certainly seems that way.
In a couple more days I might be ready to post some screenshots so you can see what I’m up to. Thanks for all the advice – it’s been extremely useful so far!
On a completely different note – Google Definitions. Define arse, web log, life, and one for Clinton, define sex.



Comments
That’s the only thing I can think of.
phpinfo()reported that PHP was compiled with XSLT (using the switches you listed). However, a call to any of the XSLT functions returned an unknown function error.Apart from the compilation switches, there’s no further mention of XSLT in my
phpinfo()output.This is a straight up Debian Woody install.
When working on windows (as I tend to do) its easiest to remove PHP and start from scratch than trying to ”add in” libraries. Dunno why, but it seems to break any other way. A clean, manual install including everything you need seems to work fine though.
What *exactly* are you doing with XML? What I mean is: are you sure the best approach is to store your data in an XML format, or would you be better generating the XML output dynamically?
I remember this tip I learned a long time ago; ”Create your application around your content. Don’t ever, ever, ever try to fit your content around your application. You’ll double/treble your project time”, and believe me, I’ve prooved this.
PHP/MySQL is perfect for shopping carts, timesheet systems, etc. Its data-centric.
PHP/XML is best suited for articles, documents, memo’s, notes, news... that sort of thing. Its document-centric.
So yeah, I think file-based XML is the way to go.
(Also it offers really easy data backup and document portability)
You wouldn’t believe how many people code in ”PHP/MySQL” or ”ASP/SQL Server” or ”JSP/PostgreSQL” or [insert chosen dicipline here] and thats it - no matter what the data is. They’ll generate a SQL database and a three-tier app for a company who just wants a 10 page website built from thier company brochure.
What about the config file? If its nice and simple, you can’t get better than an ini file. PHP’s parse_ini_file() function is faster than any file read/parse function i’ve seen yet, and it pops it into an array for you. Perfect when you just want to have one file for config, which is human readable and easy to alter. XML has its place, but for simple ”a = 1”, it just doesn’t this the mark.
;extension=php_xslt.dll