title: How can I display XML with whitespace formatting?
body: <p>I have a web page that builds an XML from an existing XML applying changes.  I want to output the new XML file in a <code>textarea</code> as a preview.  It displays any nodes that were present in the original XML with the proper whitespaces/formatting (indents and linebreaks) that the original XML had just fine, but any new nodes are all displayed on one line with no indents.  Example:</p>
  
  <pre><code>&lt;original parent node&gt;
      &lt;original child&gt;value&lt;/original child&gt;
  &lt;/original parent node&gt;
  &lt;original parent node&gt;
      &lt;new child&gt;value&lt;/new child&gt;&lt;new child&gt;value&lt;/new child&gt;&lt;new child&gt;value&lt;/new child&gt;&lt;new child&gt;value&lt;/new child&gt;&lt;new child&gt;value&lt;/new child&gt;&lt;new child&gt;value&lt;/new child&gt;
  &lt;/original parent node&gt;
  </code></pre>
  
  <p>Here is the code that writes and reads back in the XML:</p>
  
  <pre><code>$dom = new DOMDocument('1.0');
  $dom-&gt;preserveWhiteSpace = true;
  $dom-&gt;formatOutput = true;
  $dom-&gt;loadXML($xml-&gt;asXML());
  file_put_contents($file, $dom-&gt;saveXML());
  echo "&lt;textarea cols='100' rows='40'&gt;".file_get_contents($file)."&lt;/textarea&gt;";
  </code></pre>
  
  <p>I'm also using SimpleXML to manipulate the XMLS.  How can I get the proper whitespacing to display for the new nodes?</p>