XML::LibXML->new, recover flag, suppress warnings
Michael Ludwig <[email protected]>
| Newsgroups | gmane.comp.lang.perl.xml |
|---|---|
| Message-ID | <[email protected]> |
In XML::LibXML, warnings are not suppressed when specifying the recover or recover_silently flags as per the following excerpt from the manpage:
--------
recover
/parser, html, reader/
recover from errors; possible values are 0, 1, and 2
A true value turns on recovery mode which allows one to parse broken XML or HTML data. The recovery mode allows the parser to return the successfully parsed portion of the input document. This is useful for almost well-formed documents, where for example a closing tag is missing somewhere. Still, XML::LibXML will only parse until the first fatal (non-recoverable) error occurs, reporting recoverable parsing errors as warnings. To suppress even these warnings, use recover=>2.
--------
http://search.cpan.org/dist/XML-LibXML/lib/XML/LibXML/Parser.pod
Here's a test case to evidence the behaviour:
# use strict;
# use warnings;
# use utf8;
use XML::LibXML;
my $txt = <<'EOS';
<div>
<a href="/app/search?op=list&type=50">eins</a>
<!-- HTML parser error : htmlParseEntityRef: expecting ';' -->
</div>
EOS
my $prsr = XML::LibXML->new( # see perldoc XML::LibXML::Parser
recover => 2, # makes parser go on despite errors
# suppress_warnings => 1, # doesn't shut the warning off
# suppress_errors => 1, # not either
);
my $dom = $prsr->load_html( string => $txt );
print $dom->toString( 1 );
print "$_\n" for
XML::LibXML::LIBXML_DOTTED_VERSION, # 2.7.6 in my case
XML::LibXML::LIBXML_VERSION, # 20706
XML::LibXML::LIBXML_RUNTIME_VERSION; # 20707 yeah, I know ;-)
--
Michael.Ludwig (#) XING.com
_______________________________________________
Perl-XML mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs