converting xml DOMDocument to string converting xml DOMDocument to string xml xml

converting xml DOMDocument to string


The DOMDocument object can't be used as a string.

Here is how you would display the DOMDocument object as an XML string:

echo $doc->saveXML();


DOMDocument has a method SaveHTML(), it's designed to do exactly what you need.

You may display whole document by:

$doc->saveHTML();

Or just certain node:

$doc->saveHTML( $bodyNode);

DOMDocument also provides few options how to enhance how the XML is print, such as:


Try this:

$xml = $doc->saveXML($doc->documentElement);