title: java Element.setTextContent drops newlines
body: <p>I have a problem with creating an xml file.  I need to preserve the newlines in a sting retrieved from a database and stored into a node.  I haven't been able to get it to work.  I've tried the following variations.</p>
  
  <pre><code>Element ele = doc.createElement("productDescription");
  ele.setTextContent(text); // this drops the newlines.
  ele.appendChild(doc.createTextNode(text)); // this drops the newlines.
  ele.setTextContent(text.replace("\n", "&amp;#10;")); // this changes all the newlines to the text "&amp;#10;"
  </code></pre>
  
  <p>I'm outputting the document with.</p>
  
  <pre><code>String QueryResults(String query) {
    Document doc = CreateDoc(query);
    StringWriter sw = new StringWriter();
    StreamResult result = new StreamResult(sw);
    DOMSource source = new DOMSource(doc);
    try {
      docTransformer.transform(source, result);
    } catch (TransformerException ex) {
      System.out.println("Failed to convert doc to string: " + ex.getMessage());
      return null;
    }
    return sw.toString();
  }
  </code></pre>
  
  <p>A sample of the output would be.</p>
  
  <pre><code>&lt;result&gt;
    &lt;Orders&gt;
      &lt;productName&gt;Widget thingy&lt;/productName&gt;
      &lt;productDescription&gt;A really cool widget thingy.\nReally, its cool.&lt;/productDescription&gt;
    &lt;/Orders&gt;
  &lt;/result&gt;
  </code></pre>