Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-03-2006, 08:26 PM   PM User | #1
drgonzo
New to the CF scene

 
Join Date: May 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
drgonzo is an unknown quantity at this point
PHP 5 Dom Manipulation

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.
drgonzo is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:16 AM.


Advertisement
Log in to turn off these ads.