title: How to get multiple namespace definions in the root element using Java?
body: <p>I am trying to create an XML DOM file using JAVA with multiple namespace definitions in the root element.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;xmi:XMI xmi:version="2.1" 
   xmlns:uml="http://schema.omg.org/spec/UML/2.1"
   xmlns:xmi="http://schema.omg.org/spec/XMI/2.1" 
   xmlns:cns="http://www.w3c.org/2016/XML/cns"&gt;
      &lt;!--- lots of data --&gt;
  &lt;/xmi:XMI&gt;
  </code></pre>
  
  <p>I've tried several methods and haven't found the correct one.</p>
  
  <pre><code>    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
      dbf.setNamespaceAware(true);
      Document doc = dbf.newDocumentBuilder().newDocument();
      Element root = doc.createElementNS("http://schema.omg.org/spec/UML/2.1", "xmi:XMI");
      doc.appendChild(root);
  </code></pre>
  
  <p>creates my first namespace definition. </p>
  
  <pre><code> &lt;?xml version="1.0" encoding="UTF-8"?&gt;
   &lt;xmi:XMI xmlns:xmi="http://schema.omg.org/spec/XMI/2.1"&gt;
      &lt;!--- some data --&gt;
  &lt;/xmi:XMI&gt;
  </code></pre>
  
  <p>But how to create the others? I have experiented with <code>root.setAttributeNS("http://schema.omg.org/spec/UML/2.1", "uml:Model", null);</code>, but then I only get </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;xmi:XMI 
    xmlns:uml="http://schema.omg.org/spec/UML/2.1" 
    uml:Model="" 
    xmlns:xmi="http://schema.omg.org/spec/XML/2.1"/&gt;
      &lt;!--- some data --&gt;
  &lt;/xmi:XMI&gt;
  </code></pre>
  
  <p>The <code>uml:Model</code> attribute should not be there. Anyone ideas?</p>