Lately, I've been working on the Linux Users of Central Illinois web site. One of the ideas that I've been planning to implement for a while is a "news" section on the main page for both local news and news from other Linux (etc.) web sites. I was finally motivated to actually implement this (partially, at least on my test version of the site) after reading Chris Nandor's article RSS and You on perl.com.

News sites like Slashdot have started to distribute their "headlines" (and sometimes their entire stories) in an XML docment format called RSS (RDF Site Summary). Slashdot, in particular, makes their headlines available at http://slashdot.org/slashdot.rdf.

The first step to getting Slashdot's headlines on the LUCI page was to periodically fetch slashdot.rdf. I did this with a little script I wrote called getfile (that is functionally equivalent to lwp-mirror, and which will hopefully be available on my software page by the time you read this), running from cron.

The next step was to actually parse the RSS file. This is done with a module called XML::RSS (which uses XML::Parse, and which can also be used to create and manage RSS files). The code to parse slashdot.rdf looks like this (from a page generated with Apache::ePerl 1):

<h3 id="slashdot_head">
News from <a href="http://slashdot.org/">Slashdot</a>:
</h3>

<p id="slashdot">
<:  
    my $rss=new XML::RSS;
    $rss->parsefile("/home/luci/rdf/slashdot.rdf");
    my $item;
    for $item (@{$rss->{"items"}})
    {   
        print "<a href=\"", $item->{"link"}, "\">",
              $item->{"title"}, "</a><br />\n";
    }
:>
</p>

(Not that it has anything to do with Perl, but in the interest of completeness...) In the stylesheet for the site, I have the following items to try to duplicate the color of the Slashdot site, more or less:

#slashdot_head {
    background: #006562;
    color: white
}

#slashdot_head a:link, #slashdot_head a:visited { color: white }

#slashdot {
    color: black
}

#slashdot a:link { color: #006562 }
#slashdot a:visited { color: black }


Notes

1 XML::RSS version 0.8 required the following small patch to work properly under Apache::ePerl:

--- XML/RSS.pm.orig     Mon Dec 27 02:50:22 1999
+++ XML/RSS.pm  Tue Mar 14 15:02:56 2000
@@ -638,6 +638,7 @@
        #}
 }
 
+sub DESTROY {}
 
 1;
 __END__

Steven Pritchard, steve@silug.org