in reply to Caching Entities with XML::LibXML

I think to prevent XML::LibXML from loading external entities, you can pass load_ext_dtd => 0 in the constructor. That will stop you from hammering w3.org, but I think it will also somewhat hamper validation, if that's your aim.

Replies are listed 'Best First'.
Re^2: Caching Entities with XML::LibXML
by ikegami (Patriarch) on Feb 24, 2010 at 22:44 UTC
    I'm not doing any validation. Getting the entities is required for parsing. Preventing the fetching of the remote DTD without adding something in its place prevents parsing.
    use strict; use warnings; use XML::LibXML qw( ); my $parser = XML::LibXML->new( load_ext_dtd => 0, ); my $xhtml = <<'__EOI__'; <?xml version="1.0" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Test</title> </head> <body>&nbsp;</body> </html> __EOI__ $parser->parse_string($xhtml);
    :8: parser error : Entity 'nbsp' not defined <body>&nbsp;</body> ^