title: How to generate XML documents with namespaces in Python
body: <p>I'm trying to generate an XML document with namespaces, currently with Python's xml.dom.minidom:</p>
  
  <pre><code>import xml.dom.minidom
  doc = xml.dom.minidom.Document()
  el = doc.createElementNS('http://example.net/ns', 'el')
  doc.appendChild(el)
  print(doc.toprettyxml())
  </code></pre>
  
  <p>The namespace is saved (<code>doc.childNodes[0].namespaceURI</code> is <code>'http://example.net/ns'</code>), but why is it missing in the output?</p>
  
  <pre><code>&lt;?xml version="1.0" ?&gt;
  &lt;el/&gt;
  </code></pre>
  
  <p>I expect:</p>
  
  <pre><code>&lt;?xml version="1.0" ?&gt;
  &lt;el xmlns="http://example.net/ns" /&gt;
  </code></pre>
  
  <p>or</p>
  
  <pre><code>&lt;?xml version="1.0" ?&gt;
  &lt;randomid:el xmlns:randomid="http://example.net/ns" /&gt;
  </code></pre>