title: Forcing escaped characters when writing to XML
body: <p>I'm using org.w3c and javax.xml.parsers in Java for reading and writing xml files.
  When I read an xml file, the &#10; escaped line breaks will be replaced by real line breaks. When I write the content back to the file, I loose escaping and the content of the file will change unintentionally.
  so </p>
  
  <pre><code>&lt;somenode&gt;First line.&amp;#10;Second line&lt;/somenode&gt;
  </code></pre>
  
  <p>will be replaced by:</p>
  
  <pre><code>&lt;somenode&gt;First line.
  Second line.&lt;/somenode&gt;
  </code></pre>
  
  <p>Before writing xml content back to disk I tried:</p>
  
  <pre><code>String content = node.getTextContent().replace("\n","&amp;#10;");
  node.setTextContent(content);
  </code></pre>
  
  <p>Of course it does not work, it will be escaped to &amp;amp;#10; in the file.</p>
  
  <p><strong>I do not want to litter the file with CDATA tags!</strong></p>
  
  <p>What I want to do is legal XML output so there has to be a way to do it.</p>
  
  <p>Thanks in advance for any ideas :)</p>