casinoonline
New Member
I'm trying to add a childnode in an XML document with PHP and got it OK so far except one thing. Can't get it formatted correct?Here is the script:\[code\]$xmldoc = new DOMDocument();$xml->formatOutput = true;$xml->preserveWhiteSpace = false;$xmldoc->loadXML('<?xml version="1.0" encoding="ISO-8859-1"?><data> <udate>1347730639</udate> <userid>3</userid></data>');echo "<xmp>OLD:\n". $xmldoc->saveXML() ."</xmp>";$root = $xmldoc->firstChild;$newElement = $xmldoc->createElement('popup');$root->appendChild($newElement);$newText = $xmldoc->createTextNode("0");$newElement->appendChild($newText);echo "<xmp>NEW:\n". $xmldoc->saveXML() ."</xmp>";\[/code\]After adding the node I get this:\[code\]<data> <udate>1347730639</udate> <userid>3</userid><popup>0</popup></data>\[/code\]I want it to be like this:\[code\]<data> <udate>1347730639</udate> <userid>3</userid> <popup>0</popup></data>\[/code\]Where do I go wrong?Please help and thanks in advance