use XML::Checker::Parser; my %expat_options = (KeepCDATA => 1, Handlers => [ Unparsed => \&my_Unparsed_handler ]); my $parser = new XML::Checker::Parser (%expat_options); eval { local $XML::Checker::FAIL = \&my_fail; $parser->parsefile ("valid.xml"); }; if ($@) { print "Either XML::Parser (expat) threw an exception or my_fail() died."; } # Throws an exception (with die) when an error is encountered, this # will stop the parsing process. # Don't die if a warning or info message is encountered, just print a message. sub my_fail { my $code = shift; die XML::Checker::error_string ($code, @_) if $code < 200; XML::Checker::print_error ($code, @_); } sub my_Unparsed_handler { print "!"; }