Re: DOMDocument->saveXML()

From: Date: Mon, 18 Sep 2006 22:13:34 +0000
Subject: Re: DOMDocument->saveXML()
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-241909@lists.php.net to get a copy of this message
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

« previous php.general (#241909) next »