Stories
Slash Boxes
Comments
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)

gav
  (email not shown publicly)
http://www.estey.com/
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 {
    $twig->parsefile($file);
    $twig->purge;
};
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.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.