Creating an RSS Reader Application - Parsing the RSS document (Page 3 of 4 )
The next function just parses the RSS document that is allocated it.
function showparsedContents($thelocation){
parsefile($thelocation);
}
When the "Create RSS document" link is selected, a function called choicefrm() is activated. This function displays a form that requests a name for the RSS document that you want to create, and also requests that you choose between a simple RSS document or an enhanced one.

Fig 2. A form that request what type of RSS document to create...
Then based on your choice, one of the two forms are displayed. Now, let's say you chose a simple version. A function called simplefrm() will be activated which will request that you enter the required information. Here's a screen shot:

Fig 3. Simple RSS Document information form...
When you submit the form, the do_simpfrm() function is called, which processes the form variables and then creates the RSS document. Here's the function that does all that:
function do_simpfrm($filename,$mtitle,$mlink,$mdesc,$t1,$l1,
$txt1,$t2,$l2,$txt2,$t3,$l3,$txt3){
//Create the file
if($fp = fopen($filename,"a+")){
//write in the file
fwrite($fp,"<?xml version='1.0'?>rn");
fwrite($fp,"<rss version='2.0'>rn");
fwrite($fp,"<channel>rn");
fwrite($fp,"<title>".$mtitle."</title>rn");
fwrite($fp,"<link>".$mlink."</link>rn");
fwrite($fp,"<description>".$mdesc."</description>rn");
fwrite($fp,"<item>rn");
fwrite($fp,"<title>".$t1."</title>rn");
fwrite($fp,"<link>".$l1."</link>");
fwrite($fp,"<description>".$txt1."</description>rn");
fwrite($fp,"</item>rn");
fwrite($fp,"<item>rn");
fwrite($fp,"<title>".$t2."</title>rn");
fwrite($fp,"<link>".$l2."</link>rn");
fwrite($fp,"<description>".$txt2."</description>rn");
fwrite($fp,"</item>rn");
fwrite($fp,"<item>rn");
fwrite($fp,"<title>".$t3."</title>rn");
fwrite($fp,"<link>".$l3."</link>rn");
fwrite($fp,"<description>".$txt3."</description>rn");
fwrite($fp,"</item>rn");
fwrite($fp,"</channel>rn");
fwrite($fp,"</rss>");
fclose($fp);
echo "The RSS document <b>" .$filename. "</b> has been created and stored.";
}else{
echo "The file could not be created due to a system error";
}
}
And with that a simple RSS document is created.
Next: Creating an enhanced RSS document >>
More XML Articles
More By Jacques Noah