title: How to insert schemalocation in a xml document via DOM
body: <p>i create a xml document with JAXP and search a way to insert the schemalocation.
  At the moment my application produces:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;root&gt;
  ...
  &lt;/root&gt;
  </code></pre>
  
  <p>But i need:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;root xmlns="namespaceURL" 
  xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
  xs:schemaLocation="namespaceURL pathToMySchema.xsd"&gt;
  ...
  &lt;/root&gt;
  </code></pre>
  
  <p>My code:</p>
  
  <pre><code>StreamResult result = new StreamResult(writer);
  Document doc = getDocument();
  
  Transformer trans = transfac.newTransformer();
  trans.setOutputProperty(OutputKeys.INDENT, "yes");
  trans.setOutputProperty(OutputKeys.METHOD, "xml");
  trans.setOutputProperty(OutputKeys.VERSION, "1.0");
  trans.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
  
  DOMSource source = new DOMSource(depl.getAsElement(doc));
  trans.transform(source, result);
  </code></pre>
  
  <p>Thanks for your time,<br>
  Kasten</p>