View Full Version : PHP 5 Dom Manipulation

11-03-2006, 08:26 PM
I wrote some code in php4 that did transformations on xml (adding, removing children nodes) and it worked pretty well. I've started work on another project, this time using php5 and now all that work is useless. grr.

XML File - http://www.shortmat.net/catalog/catalog.xml

First I create a new item node as a dom document, then I load the catalog.xml file into another dom document. I am just trying to add the new node to the file and display the new catalog.xml.

$newitem = new DomDocument;

$item = $newitem->appendChild(new DOMElement('item'));

$name = new DOMElement('name',$_REQUEST['name']);
$price = new DOMElement('price',$_REQUEST['price']);
$dims = new DOMElement('dims',$_REQUEST['dims']);
$numpockets = new DOMElement('numpockets',$_REQUEST['numpockets']);
$desc = new DOMElement('price',$_REQUEST['desc']);
$image = new DOMElement('image','imageurl');


print $newitem->saveXML(); // <-- correctly outputs the new <item> element
print "<br/><br/>";

$catalogxml = new DOMDocument;

// code below here is not working correctly

$catalog = $catalogxml->documentElement();
print $catalog->saveXML();

I've been stuck on this for two days and I can't figure out what to do. Please help.