title: Java, XML DocumentBuilder - setting the encoding when parsing
body: <p>I'm trying to save a tree (extends <code>JTree</code>) which holds an <code>XML</code> document to a <code>DOM Object</code> having changed it's structure.</p>
  
  <p>I have created a new document object, traversed the tree to retrieve the contents successfully (including the original encoding of the <code>XML</code> document), and now have a <code>ByteArrayInputStream</code> which has the tree contents (<code>XML</code> document) with the correct encoding.</p>
  
  <p>The problem is when I parse the <code>ByteArrayInputStream</code> the encoding is changed to <code>UTF-8</code> (in the <code>XML</code> document) automatically. </p>
  
  <p>Is there a way to prevent this and use the correct encoding as provided in the <code>ByteArrayInputStream</code>. </p>
  
  <p>It's also worth adding that I have already used the<br>
      <code>transformer.setOutputProperty(OutputKeys.ENCODING, encoding)</code>  method to retrieve the right encoding.</p>
  
  <p>Any help would be appreciated.</p>