Nocturnus has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

is it possible to set options for the XML:LibXML::SAX parser? Notably, I would like to prevent the parser from resolving external (and internal, if possible) entities, and from throwing error messages relating to undefined entities.

The documentation for XML::LibXML::SAX seems to be horrible (nearly non-existent), and I didn't find a way to do that.

Thank you very much for any ideas,

Nocturnus

Replies are listed 'Best First'.
Re: How to set options for XML::LibXML:SAX
by Corion (Patriarch) on Apr 22, 2012 at 08:01 UTC

    Looking at the source, it doesn't look like you can configure it at all. It recreates the XML::LibXML object in various places, without any way of supplying your own parameters:

    sub _parse_bytestream { my ( $self, $fh ) = @_; $self->{ParserOptions}{LibParser} = XML::LibXML->new; $self->{ParserOptions}{ParseFunc} = \&XML::LibXML::parse_fh; $self->{ParserOptions}{ParseFuncParam} = $fh; $self->_parse; return $self->end_document({}); }

    You'll have to patch the module and find out how to make XML::SAX::Base pass parameters down to the implementation, and then pass these parameters on to XML::LibXML.

      Thank you very much for the precise answer. It seems that my fears have come true.

      Regards,

      Nocturnus