 <p>And when you need to inject it back into some other DOM (like your HTML page) you can export it again using the $dom->saveXML() method. The problem however is that it also exports an xml header (it's even worse for the saveHTML version). To get rid of that use this:</p> <pre><code>$xml = $dom-&gt;saveXML(); $xml = substr( $xml, strlen( "&lt;?xml version=\"1.0\"?&gt;" ) ); </code></pre>