Hi all
I'm currently messing about trying to populate an XML file from data entered in a form. I've already started off the XML file with the XML version, the RSS version and I've managed to get it so that all data entered in the form, is then sent to a database and is written to my XML file, each set of data following the last. Perfect.
Now, I'm wondering how you get to close off the XML file with </rss> when each time I add something via the form, its going to be inserted at the end of the file.
Here's the code i have at present.
CODE
<?php
// Gather details from form
$newHeadline = $_POST['headline'];
$newDate = $_POST['date'];
$newURL = $_POST['url'];
$newDescription = $_POST['description'];
$newArticle = $_POST['article'];
// Create INSERT query for new data into News table
$query = "INSERT INTO news (headline, date, url, description, article) VALUES ('$newHeadline', '$newDate', '$newURL', '$newDescription', '$newArticle')";
// Run query through connection
$result = mysql_query ($query, $connection);
//$filename = 'results.xml';
$fp = fopen('results.xml', 'a');
fwrite($fp, "\n" . '<item>' . "\n");
fwrite($fp, '<title>');
fwrite($fp, $newHeadline);
fwrite($fp, '</title>' . "\n");
fwrite($fp, '<pubDate>');
fwrite($fp, $newDate);
fwrite($fp, '</pubDate>' . "\n");
fwrite($fp, '<link>');
fwrite($fp, $newURL);
fwrite($fp, '</link>' . "\n");
fwrite($fp, '<description>');
fwrite($fp, $newDescription);
fwrite($fp, '</description>' . "\n");
fwrite($fp, '<article>');
fwrite($fp, $newArticle);
fwrite($fp, '</article>' . "\n");
fwrite($fp, '</item>' . "\n");
fclose($fp);
?>
And here is the XML file which keeps getting the form data added to.
CODE
<?xml version="1.0" ?>
<rss version="2.0">
<channel>
<title></title>
<link>/</link>
<description></description>
<image>
<url></url>
<link></link>
</image>
<item>
<title>nearly there</title>
<pubDate>Thur, 13 Nov 2008 22:57</pubDate>
<link>http://www.somethinghere.com</link>
<description>almost...</description>
<article>just need to figure out how to close off this file.</article>
</item>
So as you can see, everything between the <item></item> keeps getting added each time the form is filled in, but how on earth do i get the final </channel> and </rss> ???
Any help would be much appreciated. Thanks