title: Java Transformer, TransformerFactory messes up multiline xml comments
body: <p>I'm having a bit of trouble using Transformer/TransformerFactory to update an existing XML file (on a Wowza server).  It works great and updates correctly, but it makes a mess of multiline comments.</p>
  
  <p>The comments start out looking like this:</p>
  
  <pre><code>&lt;!--StorageDir path variables   
  ${com.wowza.wms.AppHome} - Application home directory   
  ${com.wowza.wms.ConfigHome} - Configuration home directory      
  ${com.wowza.wms.context.VHost} - Virtual host name  
  ${com.wowza.wms.context.VHostConfigHome} - Virtual host config directory        
  ${com.wowza.wms.context.Application} - Application name     
  ${com.wowza.wms.context.ApplicationInstance} - Application instance name        
  --&gt;
  </code></pre>
  
  <p>After the transform, they end up all in one line with square characters where the return carriages used to be (won't post the result here because the squares don't show, and the line wrap makes the end result look pretty much like the above block).</p>
  
  <p>This is the code I use to make the xml updates (just a snippet):</p>
  
  <pre><code>TransformerFactory tFactory = TransformerFactory.newInstance();
  tFactory.setAttribute("indent-number", new Integer(4));
  Transformer transformer = tFactory.newTransformer();
  transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
  transformer.setOutputProperty(OutputKeys.METHOD, "xml");
  transformer.setOutputProperty(OutputKeys.INDENT, "yes");
  
  DOMSource source = new DOMSource(document);
  File outFile = new File(path.getPath() + "/Application.xml");
  FileOutputStream outputStream = new FileOutputStream(outFile);
  
  StreamResult result = new StreamResult(new OutputStreamWriter(outputStream));
  transformer.transform(source, result);
  </code></pre>
  
  <p>I need to keep these multiline comments legible and correctly formatted because these xml files need to be edited by hand sometimes, and the comments are used as guides and reminders.</p>
  
  <p>Any input?  How might I get the transformers to stop mangling my comments?  Thanks very much!  :)</p>
  
  <p><strong>EDIT:</strong>  This is how the document is initially created (where appXML is the path of the Application.xml file that is going to be edited):</p>
  
  <pre><code>Document document;
  DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  DocumentBuilder builder = factory.newDocumentBuilder();
  document = builder.parse(appXML);
  </code></pre>
  
  <p>After that, I make a lot of node-specific changes... too many in total to put them all here, but there are the formats all of the changes follow:</p>
  
  <p><strong>Changing a node:</strong></p>
  
  <pre><code>Node streamType = document.getElementsByTagName("StreamType").item(0);  
  streamType.setTextContent(mountType);   
  </code></pre>
  
  <p><strong>Appending a child element</strong></p>
  
  <pre><code>Node nameNode = document.createElement("Name");
  nameNode.appendChild(document.createTextNode("utilities"));
  
  Node module = document.createElement("Module");
  module.appendChild(nameNode);
  
  Element modules = (Element)document.getElementsByTagName("Modules").item(0);
  modules.appendChild(module);
  </code></pre>
  
  <p>Hope that info helps!</p>