PHP generated XML parsing failed <p>In my CodeIgniter 2.x project with PHP 5.3.x I use following function to render Dom Document as XML response. Every things are goes fine. But generated XML parsing failed due to some malformed unexpected text (non-whitespace text outside root element).</p> <pre><code>function renderDOMAsXML(DOMDocument &amp;$dom, $format = true, $status = 200){ $dom-&gt;formatOutput = $format; $controller = &amp;get_instance(); $controller-&gt;output-&gt;set_status_header($status); $controller-&gt;output-&gt;set_header('Content-type: application/xml; charset=utf-8'); $controller-&gt;output-&gt;set_output($dom-&gt;saveXML()); } </code></pre> <p>for my curiosity I decoded the malformed unexpected text (non-whitespace text outside root element) as hexadecimal format as following.</p> <pre><code>\x00ef\x00bb\x00bf\x00ef\x00bb\x00bf\x00ef\x00bb\x00bf\x00ef\x00bb\x00bf\x00ef\x00bb\x00bf </code></pre> <p>or </p> <pre><code>\x{00ef}\x{00bb}\x{00bf}\x{00ef}\x{00bb}\x{00bf}\x{00ef}\x{00bb}\x{00bf}\x{00ef}\x{00bb}\x{00bf}\x{00ef}\x{00bb}\x{00bf} </code></pre> <p>or like this</p> <pre><code>∩╗┐∩╗┐∩╗┐∩╗┐∩╗┐ </code></pre> <p>I could not realize what's the wrong. What are the malformed unexpected text (non-whitespace text outside root element)? are they any header information? How do I could skip them as I want to render it as XML response for browser.</p>