TechTutorials - Free Computer Tutorials  







How To Parse RSS Feeds Hot
 


Added: 07/04/2005, Hits: 7,413, Rating: 0, Comments: 0, Votes: 0
Add To Favorites | Comment on this article
I recently had my first experience with RSS Feeds and finding introductory tutorials and methods for setting them up was very frustrating. As a result, I have decided to put together a short tutorial on the subject. This tutorial is a starting point for beginners and does not cover programming or XML.

In my particular situation, we were given the URL to a XML file and were trying to include the output of this file on our site. Most news feed suppliers (known as aggregators) will give you a javascript snippet to include on your site and all of the parsing is done on their end. In this case, we were getting the RSS feed from a partner and had to find a way to parse the file ourselves. After a lot of research, I finally discovered that there are a few different options for doing this. Each of these will be discussed below, but before getting started, it is a very good idea to validate the feed that you will be working with to make sure that there are not any errors. A couple of good options for this are Feed Validator and RSS Validator.

rss2html.pl
This is the option that I found to work the best for us because it is free, it allows you to parse your own files, and is easy to set up. rss2html.pl is a simple Perl script that will parse RSS feeds to an HTML file and allow you to include them on your pages using SSI includes. If your sites pages are in a different format such as PHP, ASP, etc. you will have to find a different way to import the file.

To get started with rss2html.pl, you first need to get the source code. Copy the contents of this page and paste them into notepad. Save the notepad file as rss2html.pl and save it in your cgi-bin directory. Next you need to install the necessary modules that rss2html uses.

On a Linux system, you need the XML::Parser and XML::RSS modules. Type the following from a shell prompt to get these modules and install them:

perl -MCPAN -e "install XML::Parser"
perl -MCPAN -e "install XML::RSS"

If you will be using this script on a Windows server, you must have a C compiler and nmake. To install the module go to http://search.cpan.org/dist/XML-RSS/. Next, uncompress the zip file. From a command prompt change directories (CD command) to the XML-RSS-0.5 directory and enter the following commands. Press enter after each line.

Code :

perl Makefile.PL
nmake
nmake install

The next step is to set up a cron job that will tell the parser to run at specified periods of time. In your cron job enter the following (results may vary depending on your configuration).

Code :

perl /path/to/rss2html.pl http://url.of.rssfeed > /path/to/html/output.html

You will need to replace these values with the paths and URL to match your situation. If you need help with cron, this tutorial should help.

CaRP
CaRP is mainly for use with PHP pages, however, there is supposedly a feature that will output a RSS feed to JavaScript. While this software is free, you really need to be a programmer to get it to work. The instructions are absolutely terrible and definitely not written for beginners. I was never able to get CaRP to work, but may be worth a try.

RSS Xpress
For Windows web servers, this might be a good option. I have not tried this, but it appears to have a lot of features and is free.

Online Parsers
There are several web sites that will parse your RSS feeds for you and supply you with a javascript snippet that you can add to nearly any web page. This is a very easy route to go if you don't mind trusting this to another web site. Some of them will insert a link back to their site in the feed output. Some of them offer forms allowing you to control the formatting of the output. Here are some good options:

P3K - Free service with customization form.
RSSxpress-Lite - Another free service with customization form.
RSS Digest - Free service outputs to JavaScript, PHP, or an IFRAME.
RSS to Javascript - Converts RSS, RDF and ATOM feeds into JavaScript.
Jawfish - Pay service converts feeds to JavaScript.





Comments (0)

Be the first to comment on this article


Related Items








7 Seconds Resources, Inc.




IT Showcase