RSS feed reader module
RSS feeds are simple XML files that in most cases contain article titles, external links to news articles or pages and in the "ingress" information about a news article. Here is a simplified example of a typical RSS feed structure
rss_example.xml
... wait a moment...
If you want to have a look at a full version you can download one from http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/scotland/rss.xml.
However, using a standard browser may result in the browser converting the output to a “news page” so you should have a look at the source code. From Linux/Unix you can download the full page using the
wget utility:wget http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/scotland/rss.xml
We wish to present the user a list of news items with the news title as the visible link text and the link to the news item as the real URL. In HTML it might be something like this:
<a href="http://news.bbc.co.uk/go/rss/-/1/hi/scotland/7615591.stm" >
Scottish red kite numbers soaring</a>
<br />
<a href="http://news.bbc.co.uk/go/rss/-/1/hi/scotland/7615429.stm" >
Labour launches new policy drive</a>
<br />
...
As you can see from the XML file the repeating body of news items is placed in an <
item> tag. Because we are mostly interested in the links the only thing we need is get the attributes title and link from them and have our module output them in the proper way.The RSS feed reader module
The code for the module is pretty simple. While there are quite a few RSS reader classes available we will write one here. Why? Because it is a simple task. We will use the built-in PHP
XMLReader to extract the data we need.
RSSreader_module.php
... wait a moment...
Save this file to
modules/RSSReader/RSSReader_module.phpThe template for the module
At it simplest this template might be something like this:
rss.tpl
... wait a moment...