title: #xD; and #13; while reading and writing XML file
body: <p>I have an XML file input from a network API. When I try to save this as XML file from browser, it has some excess <code>&amp;#xD;</code> in it. Problem is while trying to parse this XML data through StaX and after processing, performing some task write back to another XML format as DOM, it has <code>&amp;#13;</code> instead.</p>
  
  <p>All I want to do is to avoid these excess <code>&amp;#xD;</code> from input and <code>&amp;#13;</code> from output.
  Can't quite find a reason behind these neither a solution clearly.</p>
  
  <p>This is what I get in <strong>input</strong> XML Element value after saving to file,</p>
  
  <blockquote>
  <pre><code>Today is a fine day.&amp;#xD;
  &amp;#xD;
  So does everyday.
  </code></pre>
  </blockquote>
  
  <p>And after writing, the <strong>output</strong></p>
  
  <blockquote>
  <pre><code>Today is a fine day.&amp;#13;
  &amp;#13;
  So does everyday.
  </code></pre>
  </blockquote>
  
  <p>Actually <strong>expected and required output</strong></p>
  
  <pre><code>&lt;someNode&gt;Today is a fine day.
  
  So does everyday.
  &lt;/someNode&gt;
  </code></pre>
  
  <p>The new line in the Text value of the node is intentional and needs to be preserved as it is.</p>
  
  <p><strong>Simplified Code sample:</strong></p>
  
  <p><strong>Reading</strong> stream from API:</p>
  
  <pre><code>// Get Input XML stream from API
  URL apiURL = new URL(API_Url);
  HttpsURLConnection httpsAPIURLConn;
  httpsAPIURLConn = (HttpsURLConnection) apiURL.openConnection();
  httpsAPIURLConn.setConnectTimeout(10000); // timeout
  httpsAPIURLConn.setDoInput(true);
  InputStream inStream = httpsAPIURLConn.getInputStream();
  
  // Data stream okay, Start StaX XLIFF reader
  XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
  // This is to read entity referenced strings
  xmlInputFactory.setProperty(XMLInputFactory.IS_COALESCING, true);
  
  // StaX StreamReader
  XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(new BufferedInputStream(inStream), "UTF-8");
  
  // Read and load XML data to in-memory database to filter and process
  </code></pre>
  
  <p><strong>Writing</strong> New XML structure file after filtering and processing original data</p>
  
  <pre><code>// After processing and writing new Element structure to org.w3c.dom.Document
  // write the content into xml file
  TransformerFactory transformerFactory = TransformerFactory.newInstance();
  Transformer tr = transformerFactory.newTransformer();
  tr.setOutputProperty(OutputKeys.INDENT, "yes");
  tr.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
  tr.setOutputProperty(OutputKeys.METHOD, "xml");
  tr.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
  tr.setOutputProperty(OutputKeys.STANDALONE, "no");
  
  DOMSource source = new DOMSource(doc);
  File file = new File(xmlFilePath);
  Writer outputStream = new OutputStreamWriter(new FileOutputStream(file), "UTF-8");
  StreamResult result = new StreamResult(outputStream);
  tr.transform(source, result);
  </code></pre>
  
  <p>Not sure what exactly I missed. But any suggestions or help would be great.</p>