in reply to XML validating (no DTD)
Change
$xp->parsefile($xml_file); local $XML::Checker::FAIL = \&my_fail; [download]
to
local $XML::Checker::FAIL = \&my_fail; $xp->parsefile($xml_file); [download]
It does no good to set the error handler after the checking is done.