Re: DOMDocument->saveXML()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

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 ));

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());

It would be really nice if you could also specify a string value -- the name of the root node.

I do appreciate the time and effort in reply to my post. It forced me to relook at the method and to look into DomNode and DomNodeList. :)

thnx,
Chris
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux