title: How to declare an XML namespace prefix with DOM/PHP?
body: <p>I'm trying to produce the following XML by means of DOM/PHP5:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;root xmlns:p="myNS"&gt;
    &lt;p:x&gt;test&lt;/p:x&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>This is what I'm doing:</p>
  
  <pre><code>$xml = new DOMDocument('1.0');
  $root = $xml-&gt;createElementNS('myNS', 'root');
  $xml-&gt;appendChild($root);
  $x = $xml-&gt;createElementNS('myNS', 'x', 'test');
  $root-&gt;appendChild($x);
  echo $xml-&gt;saveXML();
  </code></pre>
  
  <p>This is what I'm getting:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;root xmlns="myNS"&gt;
    &lt;x&gt;test&lt;/x&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>What am I doing wrong? How to make this prefix working?</p>