View Full Version : Updating an XML File with PHP

12-12-2008, 06:22 AM
Dear all,

I am trying to update an existing XML file with PHP using DOMDocument. My code starts like this:

$doc = new DOMDocument();
$doc->formatOutput = true;

$start = $doc->getElementsByTagName("errors")->item(0);

$element = $doc->createElement("error");
$element = $doc->appendChild($element);

My problem is, the new elements I am trying to append are added in a single line although I am using formatOutput=true.!!

Can anyone help me on this? I would really want a good looking XML file with line breaks and indenting... Thank you in advance

12-15-2008, 12:12 PM

When I used it, it produced a neat looking XML for me, I am not sure why its happening with you. Try adding formatOutPut after loading the XML file.


Lexolution IT Services
Web Design & Development company (http://www.lexolutionit.com)