in reply to Trapping XML error using Perl

... and the problem is ... ?

Does it work? throw an error? Works only on some cases?

Please give us some more clues.

Careful with that hash Eugene.

Replies are listed 'Best First'.
Re^2: Trapping XML error using Perl
by Anonymous Monk on Jun 13, 2008 at 19:33 UTC
    It does, if the xml file is not well formatted, like:

    Software error: unclosed token at line 1810, column 6, byte 65534: <Car>N</Car> <Bus>N</Bus> < =====^ at C:/Perl/lib/XML/Parser.pm line 187 For help, please send mail to this site's webmaster, giving this error + message and the time and date of the error.


    That's what I don't want, I want to get the error before and skip this file, and not display it to the user.

      I'm afraid that you can't do that with XML::Parse because it dies on malformed XML.

      On the other hand try and see XML::SAX and XML::SAX::Exception. I think they can help you

      Careful with that hash Eugene.

        You're forgetting eval {}
        #!/usr/bin/perl -- use strict; use warnings; use XML::Parser; my $p1 = new XML::Parser(Style => 'Debug'); eval { $p1->parse('error NOW> <foo id="me">Hello World</foo>'); }; warn "CAUGHTS ANS ERRORS BOSSS: $@\n" if $@; undef $p1; __END__ CAUGHTS ANS ERRORS BOSSS: syntax error at line 1, column 0, byte 0 at ...