title: How to add a carriage return to XML output in Java
body: <p>In Java how do I output a carriage return in the resulting XML file, so that everything isn't on one line?</p>
  
  <pre><code>DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
  DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
  Document doc = docBuilder.newDocument();
  Element root = doc.createElement("requests");
  doc.appendChild(root);
  root.appendChild(request);
  
  TransformerFactory transformerFactory = TransformerFactory.newInstance();
  Transformer transformer = transformerFactory.newTransformer();
  DOMSource source = new DOMSource(doc);
  StreamResult result = new StreamResult(new File(file));
  transformer.transform(source, result);
  </code></pre>
  
  <p>The above code creates an XML file, but all on one line.</p>