title: Adding linebreak in xml file before root node
body: <p>I am trying to add line break after my comments above the root node in XML document.</p>
  
  <p>I need something like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="no"?&gt;
  &lt;!--DO NOT EDIT THIS FILE--&gt;
  &lt;projects&gt;
  &lt;/projects&gt;
  </code></pre>
  
  <p>But What I was able to get is this(Line break inside the root but I need line break after the comment):</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="UTF-8" standalone="no"?&gt;
  &lt;!--DO NOT EDIT THIS FILE--&gt;&lt;projects&gt;
  
  &lt;/projects&gt;
  </code></pre>
  
  <p>I need to add the line break just after my comment. Is there a way to do this?</p>
  
  <p>My code:</p>
  
  <pre><code>import java.io.File;
  import java.io.FileInputStream;
  
  import javax.xml.parsers.DocumentBuilder;
  import javax.xml.parsers.DocumentBuilderFactory;
  import javax.xml.transform.OutputKeys;
  import javax.xml.transform.Transformer;
  import javax.xml.transform.TransformerFactory;
  import javax.xml.transform.dom.DOMSource;
  import javax.xml.transform.stream.StreamResult;
  
  import org.w3c.dom.Comment;
  import org.w3c.dom.Document;
  import org.w3c.dom.Element;
  import org.w3c.dom.Text;
  
  public class XMLNewLine {
      /**
       * @param args
       */
      public static void main(String[] args) {
          System.out.println("Adding comment..");
  
          DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
  
          dbf.setValidating(false);
          DocumentBuilder db;
  
          try {
              Document doc;
              StreamResult result;
              result = new StreamResult(new File("abc.xml"));
              db = dbf.newDocumentBuilder();
              doc = db.parse(new FileInputStream(new File("abc.xml")));
  
              Element element = doc.getDocumentElement();
              Text lineBreak = doc.createTextNode("\n");
  
              element.appendChild(lineBreak);
              Comment comment = doc
                      .createComment("DO NOT EDIT THIS FILE");
              element.getParentNode().insertBefore(comment, element);
              doc.getDocumentElement().normalize();
              TransformerFactory transformerFactory = TransformerFactory
                      .newInstance();
              Transformer transformer = transformerFactory.newTransformer();
              DOMSource source = new DOMSource(doc);
              transformer.setOutputProperty(OutputKeys.INDENT, "yes");
              transformer.transform(source, result);
  
          } catch (Exception e) {
              // TODO Auto-generated catch block
  
          }
  
      }
  }
  </code></pre>