title: Java XML api removes whitespace before self closing tag
body: <p>I've XML file which contains only one element</p>
  
  <pre><code>&lt;Message&gt;
      &lt;Location URI ="XXX:XXX:XXX" /&gt;
  &lt;/Message&gt;
  </code></pre>
  
  <p>I want to read and print same XML using Java, but after print it loses white space before /></p>
  
  <pre><code>&lt;Message&gt;
      &lt;Location URI ="XXX:XXX:XXX"/&gt;
  &lt;/Message&gt;
  </code></pre>
  
  <p>I have tried different configuration of DocumentBuilderFactory and Transformer but the result is same.</p>
  
  <p>Any Idea?</p>
  
  <pre><code>DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  DocumentBuilder builder = factory.newDocumentBuilder();
  Document requestDocument = builder.parse(this.getClass().getResourceAsStream("/message-template.xml"));
  
  TransformerFactory tf = TransformerFactory.newInstance();
  Transformer transformer = tf.newTransformer();
  transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
  DOMSource domSource = new DOMSource(requestDocument);
  StringWriter writer = new StringWriter();
  StreamResult result = new StreamResult(writer);
  transformer.transform(domSource, result);
  
  System.out.println(writer.toString());
  </code></pre>