creating multiple xml nodes with same namespaces in php

Necross

New Member
I have the following code \[code\] $dom = new DOMDocument('1.0', 'utf-8'); $headerNS = $dom->createElementNS('http://somenamespace', 'ttauth:authHeader'); $accesuser = $dom->createElementNS('http://somenamespace', 'ttauth:Accessuser','aassdd'); $accesscode = $dom->createElementNS('http://somenamespace', 'ttauth:Accesscode','aassdd'); $headerNS->appendChild($accesuser); $headerNS->appendChild($accesscode); echo "<pre>"; echo ($dom->saveXML($headerNS)); echo "</pre>";\[/code\]IT will produce the following xml as output\[code\]<?xml version="1.0" ?><ttauth:authHeader xmlns:ttauth="http://somenamespace"><ttauth:Accessuser> ApiUserFor136</ttauth:Accessuser><ttauth:Accesscode> test1234</ttauth:Accesscode></ttauth:authHeader>\[/code\]But I want the following output\[code\]<ttauth:authHeader xmlns:ttauth="http://somenamespace"> <ttauth:Accessuser xmlns:ttauth="http://somenamespace"> aassdd </ttauth:Accessuser> <ttauth:Accesscode xmlns:ttauth="somenamespace"> aassdd </ttauth:Accesscode></ttauth:authHeader>\[/code\]See the xmlns is not included in elements other than root element but I want xmlns to be included in all elements Is there anything I am doing wrong ??
 
Back
Top