02-05-2008, 10:35 PM
|
#8 (permalink)
|
|
The Acquainted
Join Date: Jan 2008
Posts: 119
Thanks: 21
|
Hello all,
So I have loaded the XML file into the dom, however, each time it still overwrites it with this code:
PHP Code:
$dom = new DomDocument('1.0'); $dom -> loadXML('posts.xml');
I have tried this:
PHP Code:
$dom = DomDocument(); $dom -> loadXML('posts.xml');
...but it doesn't like it...
Here is my whole dom xml creator... I think it is almost there... just the overwrite problem. I don't understand that.
PHP Code:
//################### XML #################################
//Creates XML string and XML document using the DOM $dom = DomDocument(); $dom -> loadXML('posts.xml'); //add root - <rss> $rss = $dom->appendChild($dom->createElement('rss')); //add <channel> element to <RSS> $channel = $rss->appendChild($dom->createElement('channel')); //add <item> element to <channel> $item = $channel->appendChild($dom->createElement('item')); //add <title> element to <item> $title = $item->appendChild($dom->createElement('title')); //add <body> element to <item> $description = $item->appendChild($dom->createElement('description')); //add <category> element to <item> $category = $item->appendChild($dom->createElement('category')); //add <pubDate> element to <item> $pubDate = $item->appendChild($dom->createElement('pubDate')); //add <link> element to <item> $link = $item->appendChild($dom->createElement('link')); //add <author> element to <item> $author = $item->appendChild($dom->createElement('author')); //add <title> text node element to <title> $title->appendChild( $dom->createTextNode($ptitle)); $description->appendChild( $dom->createTextNode($pdescription)); $category->appendChild( $dom->createTextNode($pcategory)); $pubDate->appendChild( $dom->createTextNode($todaysdate)); $link->appendChild( $dom->createTextNode($plink)); $author->appendChild( $dom->createTextNode($pauthor)); //generate xml $dom->formatOutput = true; // set the formatOutput attribute of // domDocument to true // save XML as string or file $test1 = $dom->saveXML(); // put string in test1 $dom->save('posts.xml'); // save as file
########## XML END ##########################################
|
|
|
|