Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

gav (2710)

  (email not shown publicly)
AOL IM: flufflegavin (Add Buddy, Send Message)

Hacker in NYC.

Journal of gav (2710)

Wednesday May 28, 2003
02:57 PM

dealing with errors in XML

[ #12483 ]

I've been working on processing RSS feeds over the last few days or so. I had problems with one feed and an invalid character which was killing the parser so I hacked this together:

PARSE_XML: eval {
if ($@) {
    if ($@ =~ /not well-formed \(invalid token\) at line \d+, column \d+, byte (\d+)/) {
        open my $fh, '+<', $file or die "Can't update '$file': $!";
        seek $fh, $1, 0;
        print {$fh} ' ';
        close $fh;
        goto PARSE_XML;
    } else {
        die "Error parsing '$file':\n$@";

Is there something subtle I'm missing? For my purposes this works well, especially as if the author publishes the same <item> again and fixes the problem, the error will be overwritten.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.