Firefox is jolly good isn't it? Personas are jolly good too and I've done this one for work:
Now to try some Op. Art ones... ;-)
Passed our usual mooring at 06:30 after turning around and reached Baits Bite Lock at 07:00. You can tell it’s been a while since we’ve been through a lock as it seemed to take ages to get through. We hit Clayhithe at 07:40 and 08:12 saw us leaving Bottisham Lock. A fair old chug along the Cam saw us hitting Pope’s Corner and joining the Great Ouse at 09:45 and leaving the Cam. Got to the Lazy Otter at 10:30, passing a swan’s nest on our right, just around the corner after the dry dock, 5 minutes or so later we were under the A10. We passed 20 pence Marina at 11:00 where there were a couple of wooden wrecked boats - one half in the water and the other sitting on the bank, surrounded by undergrowth.
At about midday we passed Frog Hall, 12:30 saw us parallel the B1050 and we left the Hermitage Lock into Earith at 13:00. After a magnificent carvery at The Riverside Hotel and Restaurant (Yummy!) a little rest was required.
I've been working on something for ages which involved creating some XML formatted data using PHP. PHPs implementation of XML has come on leaps and bounds, it seems, and I must admit to being pretty happy with the results using PHPs DOM implementation. So I uploaded the XML to its target API and nothing happened. And nothing kept happening, over and over again...
After a fair bit of head-scratching and trying any number of things. I tried to see if the XML was broken somehow and managed to run foul of trying to print an XML Object before converting it to a string with saveXML()... oops! Then I thought about the XML Prolog and how the examples of using the API I'd seen hadn't had the whole <?xml version="1.0"?> at the beginning of the XML. Now how was a going to get rid of it?
At first I just echoed the XML to a browser and copied the resultant XML into Boxer (and sure, who wouldn't use Boxer with it's lovely Format XML tool?). Then I removed the Prolog and copied it into a string variable using the "here document" syntax and tried to upload that and all worked well. A bit clunky but it worked!.
How to remove the Prolog programmatically though?
I got to thinking about my initial fascination with XML and the stuff I read in 2004 or so and remembered XSL. PHP can use XSL so I did a bit of research and came up with this XSL file:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output omit-xml-declaration="yes"/> <xsl:template match="node()|@*"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> </xsl:copy> </xsl:template> </xsl:stylesheet>
Then it was a simple matter to put the following in the script:
// Load XML file $xsl = new DOMDocument; $xsl->load('removeProlog.xsl', LIBXML_NOCDATA); // Configure the transformer $proc = new XSLTProcessor; // and attach the xsl rules $proc->importStyleSheet($xsl); // Replace the XML with the transformed XML $xml = $proc->transformToXML($xml);
Hey Presto, all done and my hair can get back to growing ;-)