Chris Boget wrote:
Perhaps you missed my reply.
If you pass the root node then you get the entire document without the
XML declaration.
That's both elegant and built-in.
In the future there will be an save option to perform this. This was
only made possible in recent libxml releases so has not been enabled yet
in DOM (although the constant has been defined in ext/libxml).
I didn't miss it. But you have to pass in the root DomNode object. The
only way to get it is by doing the following:
$nodeList = $doc->getElementsByTagname( 'RootTagName' );
echo $doc->saveXML( $nodeList->item( 0 ));
echo $doc->saveXML($doc->documentElement);
So unless your root node has an ID, that seems pretty excessive. Now
you have the wasted resources that $nodeList is using. While it is
crude, I believe it is both faster and less resource intensive to just do:
echo str_replace( '<?xml version="1.0"?>', '', $doc->saveXML());
Doing that (although it wont work if encoding is also output in xml
declaration) also maintains document encoding. Doing the previous will
output the document element and its subtree in UTF-8 (of course this is
to be expected as you are dropping any possibility of providing an
indication of the encoding)
It would be really nice if you could also specify a string value -- the
name of the root node.
Why? documentElement property works just fine and is much more flexible.
Rob
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php