title: Adding qualified XML element doesn't inherit namespace URI
body: <p>How can I append an element with a ns-prefix to another and make it inherit namespaceURI mappings from document?  </p>
  
  <p>As an example: Instantiating a document parsing an XML string: The <code>pp:q</code> element inherits <code>namespaceURI == 'abc'</code> from <code>root</code> element, but appending a new element <code>pp:q</code> to <code>root</code>, the new element has <code>namespaceURI == null</code>  </p>
  
  <pre><code>doc = new DOMParser().parseFromString(
      '&lt;root xmlns:pp="abc"&gt;'
         +'&lt;pp:q/&gt;'
         +'&lt;q/&gt;'
      +'&lt;/root&gt;'
      ,'text/xml');
  root = doc.firstChild;
  
  x = root.getElementsByTagName("pp:q").item(0);
  console.log(x.namespaceURI);       // logs abc
  
  y = doc.createElement('pp:q')
  root.appendChild(y)
  console.log(y.namespaceURI);       //logs null
  </code></pre>
  
  <p>This example ran in <code>nodejs</code> using <code>xmldom</code> <a href="https://github.com/jindw/xmldom" rel="nofollow">library</a> </p>
  
  <p>[edited below in response to kjhughes]</p>
  
  <p>I tried <code>createElementNS</code> too, but i feel there's something wrong this way too..<br>
  appending these lines to the code:</p>
  
  <pre><code>a = doc.createElementNS('abc', 'pp:q');
  root.appendChild(a)
  console.log(a.namespaceURI);       //abc --- i may say it works, 
                                     //even though i'm required using  
                                     //both prefix *and* namespaceURI manually
                                     //while for the parsed element (x)
                                     //a lookup has been succesfully issued
                                     // but ... 
  
  a1 = doc.createElementNS('abc', 'xx:q');
  root.appendChild(a1)
  console.log(a1.namespaceURI);       //abc --- but prefix is xx! not according to xmlns declaration!
  
  b = doc.createElementNS('xyz', 'VV:q');
  root.appendChild(b)
  console.log(b.namespaceURI);       //xyz  --- I can write anything!
  
  console.log(String(doc));          //&lt;root xmlns:pp="abc"&gt;&lt;pp:q/&gt;&lt;q/&gt;&lt;pp:q/&gt;&lt;xx:q/&gt;&lt;VV:q/&gt;&lt;/root&gt; 
  </code></pre>