Removing <?xml version="1.0"?> from the output of XSLTProcessor->transformToXml()
<xsl:output method="html" />
Thanks to this post on php.net for the answer:
http://us3.php.net/manual/en/xsltprocessor.transformtoxml.php#80887
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)
<xsl:output method="html" />
<?php class xml { var $dom; var $uri; function xml($uri) { $this->dom = new DOMDocument(); if(preg_match('/\.xml$/', $uri)) { $this->uri = $uri; } else { $this->uri = $this->create($uri); } $this->dom->load($this->uri); } function set($query, $value) { $path = new DOMXPath($this->dom); $nodes = $path->query($query); $nodes->item(0)->nodeValue = $value; } function get($query) { $path = new DOMXPath($this->dom); $nodes = $path->query($query); return $nodes->item(0)->nodeValue; } function save() { $this->dom->save($this->uri); } function create($uri) { // Build the URI of the template file. $template = sprintf('%s/0.xml', $uri); // If the directory doesn't exist, we can't really // do anything. if(!is_dir($uri)) { exit('No directory'); } // If the template file doesn't exist, we cannot // create a new file automatically. if(!file_exists($template)) { exit('No template'); } // Load the template XML into our DOMDocument. $this->dom->load($template); // Scan the directory into an array. $dir = scandir($uri); // Pull out the highest ID $id = str_replace('.xml', '', array_pop($dir)); // Add one to it $id++; // Construct the new path with the new ID $uri = sprintf('%s/%s.xml', $uri, $id); // Save the new file $this->dom->save($uri); // Return the URI of the new XML file. return $uri; } } // The following code will create a new XML file // under the directory /var/www/data/users. $x = new xml('/var/www/data/users'); $x->set('//user/name', 'John Doe'); $x->save(); ?>