Home arrow XML arrow Page 3 - Creating an RSS Reader Application

Parsing the RSS document - XML

In the previous two articles we discussed how to read and build an RSS document with PHP. In this article we will create an application that uses the concepts discussed in the other two articles. So letís go straight to the coding.

TABLE OF CONTENTS:
  1. Creating an RSS Reader Application
  2. Code
  3. Parsing the RSS document
  4. Creating an enhanced RSS document
By: Jacques Noah
Rating: starstarstarstarstar / 14
February 20, 2007

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

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.



 
 
>>> More XML Articles          >>> More By Jacques Noah
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

XML ARTICLES

- Google Docs and Xpath Data Functions
- Flex Array Collection Sort and Filtering
- The Flex Tree Control
- Flex List Controls
- Working with Flex and Datagrids
- How to Set Up Podcasting and Vodcasting
- Creating an RSS Reader Application
- Building an RSS File
- An Introduction to XUL Part 6
- An Introduction to XUL Part 5
- An Introduction to XUL Part 4
- An Introduction to XUL Part 3
- An Introduction to XUL Part 2
- An Introduction to XUL Part 1
- XML Matters: Practical XML Data Design and M...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: