set_document_locator() doesn't calls with XML::LibXML::SAX

Issue #7 new
Alex Batyrshin
created an issue

Hello,

Im trying to use LibXML for my SAX parser. But my handler for set_document_locator() doesnt executes.

xmllint --version: xmllint: using libxml version 20902

XML::LibXM->VERSION: 2.0124

PS. With XML::SAX::PurePerl everything works like expected.

use Carp ();

use XML::LibXML;
use XML::LibXML::SAX;

my $handler = MyHandler->new();

#use XML::SAX::ParserFactory;
#$XML::SAX::ParserPackage = "XML::SAX::PurePerl";
#my $parser = XML::SAX::ParserFactory->parser( Handler => $handler );

my $parser = XML::LibXML::SAX->new( Handler => $handler );

my $doc = $parser->parse_file($ARGV[0]);

package MyHandler;
use base qw(XML::SAX::Base);

sub set_document_locator {
    warn Carp::longmess("call set_document_locator()");

    my ($self, $data) = @_;
    $self->{locator} = $data;
}

sub start_element {
    my ($self, $el) = @_;
    warn "start_element: $el->{Name} at line $self->{locator}->{LineNumber}\n";
}

1;

# $ cat test.xml 
# <root>
#     <foo att1="11">
#         <bar att2="22" />
#     </foo>
# </root>
#
# $ perl sax.pl test.xml 
# start_element: root at line 
# start_element: foo at line 
# start_element: bar at line 

Comments (9)

  1. Shlomi Fish repo owner

    Alex Bayrshin : hi! Thanks for the report.

    I investigated a bit and found these resources:

    For now , patches would be welcome, but I don't think it's a priority.

  2. Alex Batyrshin reporter

    Im newbie for XS and my last C practise was long time ago.

    Support for PublicId, SystemId, XMLVersion and Encoding is limited by libxml. Maybe it will be better to remove it from patch.

  3. Log in to comment