Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Perl program for displaying RSS feed?

by Alatar (Beadle)
on May 07, 2004 at 12:50 UTC ( [id://351431]=perlquestion: print w/replies, xml ) Need Help??

Alatar has asked for the wisdom of the Perl Monks concerning the following question:

I've googled unsuccesfully for this. What I really need is a simple perl program that will parse the xml output of an rss feed into standard html links. The xml is very basic, as follows:
<?xml version="1.0" encoding="ISO-8859-1" ?> - <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xml +ns="http://purl.org/rss/1.0/"> - <channel rdf:about="http://www.shannonlan.com"> <title>www.shannonlan.com</title> <link>http://www.shannonlan.com/cgi-bin/index.cgi</link> <description>www.shannonlan.com - News to Go</description> - <items> - <rdf:Seq> <rdf:li resource="http://www.shannonlan.com/cgi-bin/index.cgi?action +=viewnews&id=248" /> <rdf:li resource="http://www.shannonlan.com/cgi-bin/index.cgi?action +=viewnews&id=247" /> <rdf:li resource="http://www.shannonlan.com/cgi-bin/index.cgi?action +=viewnews&id=246" /> <rdf:li resource="http://www.shannonlan.com/cgi-bin/index.cgi?action +=viewnews&id=245" /> <rdf:li resource="http://www.shannonlan.com/cgi-bin/index.cgi?action +=viewnews&id=244" /> <rdf:li resource="http://www.shannonlan.com/cgi-bin/index.cgi?action +=viewnews&id=243" /> <rdf:li resource="http://www.shannonlan.com/cgi-bin/index.cgi?action +=viewnews&id=242" /> <rdf:li resource="http://www.shannonlan.com/cgi-bin/index.cgi?action +=viewnews&id=241" /> <rdf:li resource="http://www.shannonlan.com/cgi-bin/index.cgi?action +=viewnews&id=240" /> <rdf:li resource="http://www.shannonlan.com/cgi-bin/index.cgi?action +=viewnews&id=239" /> </rdf:Seq> </items> </channel> - <item rdf:about="http://www.shannonlan.com/cgi-bin/index.cgi?action= +viewnews&id=248"> <title>More B5 in the works?</title> <link>http://www.shannonlan.com/cgi-bin/index.cgi?action=viewnews&id +=248</link> </item> - <item rdf:about="http://www.shannonlan.com/cgi-bin/index.cgi?action= +viewnews&id=247"> <title>Babylon 5 Season 5 DVD Box Set Review</title> <link>http://www.shannonlan.com/cgi-bin/index.cgi?action=viewnews&id +=247</link> </item> - <item rdf:about="http://www.shannonlan.com/cgi-bin/index.cgi?action= +viewnews&id=246"> <title>Latest Trailer for Battle for Middle Earth</title> <link>http://www.shannonlan.com/cgi-bin/index.cgi?action=viewnews&id +=246</link> </item> - <item rdf:about="http://www.shannonlan.com/cgi-bin/index.cgi?action= +viewnews&id=245"> <title>Free Tribes and Tribes 2!</title> <link>http://www.shannonlan.com/cgi-bin/index.cgi?action=viewnews&id +=245</link> </item> - <item rdf:about="http://www.shannonlan.com/cgi-bin/index.cgi?action= +viewnews&id=244"> <title>ATi Unveils new Graphics Card</title> <link>http://www.shannonlan.com/cgi-bin/index.cgi?action=viewnews&id +=244</link> </item> - <item rdf:about="http://www.shannonlan.com/cgi-bin/index.cgi?action= +viewnews&id=243"> <title>SASSER virus!</title> <link>http://www.shannonlan.com/cgi-bin/index.cgi?action=viewnews&id +=243</link> </item> - <item rdf:about="http://www.shannonlan.com/cgi-bin/index.cgi?action= +viewnews&id=242"> <title>THG Shows Us How...</title> <link>http://www.shannonlan.com/cgi-bin/index.cgi?action=viewnews&id +=242</link> </item> - <item rdf:about="http://www.shannonlan.com/cgi-bin/index.cgi?action= +viewnews&id=241"> <title>First Unreal Tournament 2004 patch coming soon?</title> <link>http://www.shannonlan.com/cgi-bin/index.cgi?action=viewnews&id +=241</link> </item> - <item rdf:about="http://www.shannonlan.com/cgi-bin/index.cgi?action= +viewnews&id=240"> <title>FREE Softimage Experience for Half-Life 2</title> <link>http://www.shannonlan.com/cgi-bin/index.cgi?action=viewnews&id +=240</link> </item> - <item rdf:about="http://www.shannonlan.com/cgi-bin/index.cgi?action= +viewnews&id=239"> <title>EA Games: The Third Age</title> <link>http://www.shannonlan.com/cgi-bin/index.cgi?action=viewnews&id +=239</link> </item> </rdf:RDF>
As you can see this is simply a set of Http Links. I was surprised to find that no parser of this sort appears to be available. I found several Javascript and PHP solutions, but none in Perl.

Oh, and just a proviso, I am running my site on a remote server so I can't install Perl Modules, everything needs to be pretty much standard.

Thanks,
Alatar

Replies are listed 'Best First'.
Re: Perl program for displaying RSS feed?
by crouchingpenguin (Priest) on May 07, 2004 at 13:03 UTC

    Use XML::RSS installed locally within your home directory. Here is an example:

    #!/usr/bin/perl use strict; use warnings; use XML::RSS; use lib './path/to/home/dir/perl/libs'; # optionally download via a url # or slurp in a file use LWP::Simple; my $url = "http://someurl/file.rss"; my $document = get($url); my $rss = new XML::RSS(Style => 'Debug'); $rss->parse($document); foreach my $item (@{$rss->{'items'}}) { print "<a href=\"$item->{link}\">$item->{title}</a>\n"; }

    cp
    ----
    "Never be afraid to try something new. Remember, amateurs built the ark. Professionals built the Titanic."
Re: Perl program for displaying RSS feed?
by Ven'Tatsu (Deacon) on May 07, 2004 at 13:47 UTC
    I've tried quite a few modules for parsing RSS feeds.
    XML::Simple
    XML::RSS
    XML::RSS::Parser
    XML::RSS::Parser::Lite
    XML::RSS::Feed
    XML::RSSLite
    All of these do the job, but IIRC XML::RSS::Parser::Lite is the only one that does not use XML::Parser which requires C compiler to install it if it's not installed already.

    In the end I chose XML::RSSLite becaue it had the smallest memory footprint for the data I was using, which was critical for me, it may not be for you.
Re: Perl program for displaying RSS feed?
by saintmike (Vicar) on May 07, 2004 at 18:26 UTC
    If you want to look at some really slick code doing that, merlyn's latest Perls of Wisdom column in the June 2004 issue of Linux Magazine features a nice tabbed RSS-displaying GUI.

    It's not available online yet (but will be eventually).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://351431]
Approved by Paulster2
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2024-04-18 10:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found