View Single Post
Old 01-18-2008, 04:15 AM   #4 (permalink)
sketchMedia
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

i can think of 2 posts that you may find useful although they both kinda require some XML background knowledge:
Generating XML from a Mysql DB with PHP's DOM functions (part one)

TalkPHP - Creating RSS documents with the DOM API

yea the php dom functions are really the best and indeed the easiest way to create XML docs in my opinion.

this should hopefully get you started:
PHP Code:
$pDOMdoc = new DomDocument();

$pDOMdoc->load('xmldoc.xml');//load your exsisting xml doc

//get the posts node in the xml

$postsNode $pDOMdoc->getElementsByTagName('posts')->item(0);

//create new post add it to <posts>
$postNode $pDOMdoc->createElement('post');
$postNode $postsNode->appendChild($postNode);

//creae title node add to <post>
$titleNode $pDOMdoc->createElement('title');
$titleNode $postNode->appendChild($titleNode);
//add text node to the new title node
$titleTextNode $pDOMdoc->createTextNode($title);
$titleTextNode $titleNode->appendChild($titleTextNode);

//create catagory node add it to <post>
$catNode $pDOMdoc->createElement('catagory');
$catNode $postNode->appendChild($catNode);
//add text node to catagory node
$catTextNode $pDOMdoc->createTextNode($catagory);
$catTextNode $catNode->appendChild($catTextNode);

$pubDateNode $pDOMdoc->createElement('pubDate');
$pubDateNode $postNode->appendChild($pubDateNode);
$pubDateTextNode $pDOMdoc->createTextNode($date);
$pubDateTextNode $pubDateNode->appendChild($pubDateTextNode);


echo 
$pDOMdoc->save('xmldoc.xml'); 
this is based off the xml tree you posted:

<?xml version="1.0" standalone="yes"?>
<posts>
<post>
<title>Some people like meat.</title>
<category>Meat</category>
<pubDate>2008-January-15</pubDate>
</post>
</posts>
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)

Last edited by sketchMedia : 01-18-2008 at 08:56 AM. Reason: managed mispell 'text' 3 or 4 times
sketchMedia is offline  
Reply With Quote