title: How to suppress the xml element added by Transformer of javax.xml.transform.Transformer
body: <p>I've been using the Java APIs to parse an XML file so I could add, remove, or update elements/attributes. Everything works the way I want, except that the <code>Transformer</code> object I'm using adds <code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;</code> to the beginning of the XML file. I was wondering if there is a way to suppress this.</p>
  
  <p>P.S. I also noticed that this top-voted <a href="https://stackoverflow.com/questions/632043/how-do-i-extract-child-element-from-xml-to-a-string-in-java">answer</a> mentioned that we might be able to supress it. </p>
  
  <pre><code>DOMSource source = new DOMSource(document);
  TransformerFactory tFactory = TransformerFactory.newInstance();
  Transformer transformer = tFactory.newTransformer();
  FileOutputStream fout = new FileOutputStream(new File(outputFile));            
  StreamResult result = new StreamResult(fout);
  transformer.transform(source, result);
  fout.close();
  </code></pre>
  
  <p>The original document does not contain <code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;</code></p>