All in the <head> – Ponderings and code by Drew McLellan –

Making Progress

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.