How to declare an XML namespace prefix with DOM/PHP?

Boyd

New Member
I'm trying to produce the following XML by means of DOM/PHP5:\[code\]<?xml version="1.0"?><root xmlns:p="myNS"> <p:x>test</p:x></root>\[/code\]This is what I'm doing:\[code\]$xml = new DOMDocument('1.0');$root = $xml->createElementNS('myNS', 'root');$xml->appendChild($root);$x = $xml->createElementNS('myNS', 'x', 'test');$root->appendChild($x);echo $xml->saveXML();\[/code\]This is what I'm getting:\[code\]<?xml version="1.0"?><root xmlns="myNS"> <x>test</x></root>\[/code\]What am I doing wrong? How to make this prefix working?
 
Top