in reply to Checking XML well-formedness

It is indeed horrible that XML::Simple dies on you on bad XML (a module should never die).
Wrapping it in an eval() works, but is ugly and takes quite some execution time.
A quick search on google gave me this: perl XML well-formednes checker

Replies are listed 'Best First'.
Don't knock die (was Checking XML well-formedness)
by grantm (Parson) on Feb 26, 2003 at 08:42 UTC
    It is indeed horrible that XML::Simple dies on you on bad XML (a module should never die).

    Without wanting to sound defensive :-) ... Calling 'die' is Perl's mechanism for throwing an exception. Using 'eval' to catch exceptions should be part of your everyday programming style. If that's not how you're handling errors in say DBI then you need to read up on what you're missing.

    Please don't perpetuate the myth that 'eval' is costly. If you eval a string then it is true that Perl's compiler must be reinvoked to parse the string - that cost may be significant in some circumstances. However if you use eval to wrap a code block then the code in that block is compiled during the initial parse and the overhead imposed by eval is comparable to the overhead of calling a subroutine.

    In general, a module should not call 'die' though. In general, it should 'use Carp' and 'croak' on errors. This will give the user of the module a better indication of where in their code the problem is being triggered.

    Here's a Perl one-liner I use for checking well-formedness from the command line:

    perl -MXML::Parser -e "XML::Parser->new( ErrorContext => 3 )->parsefile(shift)" filename