title: java transform to html with doctype
body: <p>I am trying to create an html 5 output from java transformer.   I have </p>
  
  <pre><code>DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
  DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
  
  Document doc = docBuilder.newDocument();
  
  Element html= doc.createElement("html");
  .... //populate the html element
  
  TransformerFactory transformerFactory = TransformerFactory.newInstance();
  Transformer transformer = transformerFactory.newTransformer();
  
  DOMSource domSource = new DOMSource(html);
  StreamResult result = new StreamResult(new File(fileLocation));
  transformer.setOutputProperty(OutputKeys.METHOD, "html");
  transformer.transform(domSource, result);
  </code></pre>
  
  <p>This works great and creates the html file for me as I want.  but it doesn't have &lt;!DOCTYPE html> at the top and I can't figure out how to get that.  Looking at the documentation on transformer I am only seeing how to turn on or off the xml version of the header.  </p>
  
  <p>As you can see in my code I tried to set the output keys method to html and I have tried to implement what is suggested <a href="http://www.thecodingforums.com/threads/setting-doctype-to-a-dom-document.139420/" rel="nofollow">here</a> but the html files generated still don't have the doc type line.  </p>
  
  <p>Another option I have pondered is to create a doctype element but I don't know how to associate it with my html element.  </p>