|
NAMEXML::Checker::Parser - an XML::Parser that validates at parse timeSYNOPSISuse 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 ("fail.xml"); }; if ($@) { # Either XML::Parser (expat) threw an exception or my_fail() died. ... your error handling code here ... } # 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, @_); } DESCRIPTIONXML::Checker::Parser extends XML::ParserI hope the example in the SYNOPSIS says it all, just use XML::Checker::Parser as if it were an XML::Parser. See XML::Parser for the supported (expat) options. You can also derive your parser from XML::Checker::Parser instead of from XML::Parser. All you should have to do is replace: package MyParser; @ISA = qw( XML::Parser ); with: package MyParser; @ISA = qw( XML::Checker::Parser ); XML::Checker::Parser constructor$parser = new XML::Checker::Parser (SkipExternalDTD => 1, SkipInsignifWS => 1); The constructor takes the same parameters as XML::Parser with the following additions:
External DTDsXML::Checker::Parser will try to load and parse external DTDs that are referenced in DOCTYPE definitions unless you set the SkipExternalDTD option to 1 (the default setting is 0.) See CAVEATS for details on what is not supported by XML::Checker::Parser.XML::Parser (version 2.27 and up) does a much better job at reading external DTDs, because recently external DTD parsing was added to expat. Make sure you set the XML::Parser option ParseParamEnt to 1 and the XML::Checker::Parser option SkipExternalDTD to 1. (They can both be set in the XML::Checker::Parser constructor.) When external DTDs are parsed by XML::Checker::Parser, they are located in the following order:
Static methods related to External DTDs
Switching user handlers at parse timeYou should be able to use setHandlers() just as in XML::Parser. (Using setHandlers has not been tested yet.)Error handlingXML::Checker::Parser routes the fail handler through XML::Checker::Parser::fail_add_context() before calling your fail handler (i.e. the global fail handler: $XML::Checker::FAIL. See "ERROR_HANDLING" in XML::Checker.) It adds the (line, column, byte) information from XML::Parser to the error context (unless it was the end of the XML document.)Supported XML::Parser handlersOnly the following XML::Parser handlers are currently routed through XML::Checker: Init, Final, Char, Start, End, Element, Attlist, Doctype, Unparsed, Notation.CAVEATSWhen using XML::Checker::Parser to parse external DTDs (i.e. with SkipExternalDTD => 0), expect trouble when your external DTD contains parameter entities inside declarations or conditional sections. The external DTD should probably have the same encoding as the orignal XML document.AUTHORSend bug reports, hints, tips, suggestions to Enno Derksen at <enno@att.com>.SEE ALSOXML::Checker ("SEE_ALSO" in XML::Checker), XML::Parser
Visit the GSP FreeBSD Man Page Interface. |