Dear deities,
I am writing an RSS aggregator and have chosen the XML::RSS parser to read the feeds. I have it all working except when there is an error in the feeds XML file. The documentation for XML::RSS states that a die is produced when there is an error in the parsed XML but I would like to trap this error and not die. I would then do a next to continue onto the next feed, maybe generating my own error message etc.
I am not sure how to wrap the XML::RSS in some form of error checking...
Example pseudo code:
!/usr/bin/perl -T
$| = 1;
use strict;
use warnings;
use XML::RSS;
use LWP::Simple;
use POSIX qw(strftime);
my $there_is_a_feed_to_be_read = "true";
my $url_to_read = "http://xxx.xml";
my $url2parse;
my $rss;
while ( $there_is_a_feed_to_be_read ) {
$rss = new XML::RSS;
$url2parse = get( $url_to_read );
die "Could not retrieve $url_to_read" unless $url2parse;
# all works up to this point but if there is an error in the
# XML being read the next command chokes.
# What I am looking for is some sort of wrapper to do a next
# if there is a problem so we just step over the faulty feed
$rss->parse($url2parse);
# deal with the returned XML information here
# .
# .
# .
}
Not wanting to name names but at the present time the
following feed has a raw & symbol in the text that the
parser is tripping over.
http://developer.apple.com/rss/adcheadlines.rss
Many thanks in advance
3d
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.