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.

PHP Code:
$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');

$item->setAttribute('category',$_REQUEST['category']);
$item->setAttribute('id',"newid");
$item->appendChild($name);
$item->appendChild($price);
$item->appendChild($dims);
$item->appendChild($numpockets);
$item->appendChild($desc);
$item->appendChild($image);
$image->setAttribute('thumb','imagethumburl');

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

$catalogxml = new DOMDocument;
$catalogxml->load("catalog.xml");

// code below here is not working correctly

$catalog $catalogxml->documentElement();
$catalog->appendChild($item);
print 
$catalog->saveXML(); 
I've been stuck on this for two days and I can't figure out what to do. Please help.