in reply to XML-Parser-PerlSAX how to get the BytePosition value

I don't understand question 1, location is a method.
http://search.cpan.org/src/KMACLEOD/libxml-perl-0.08/lib/XML/Parser/PerlSAX.pm
sub location { my $self = shift; my $expat = $self->{Expat}; my @properties = ( ColumnNumber => $expat->current_column, LineNumber => $expat->current_line, BytePosition => $expat->current_byte, Base => $expat->base ); # FIXME these locations change while parsing external entities push (@properties, PublicId => $self->{Source}{PublicId}) if (defined $self->{Source}{PublicId}); push (@properties, SystemId => $self->{Source}{SystemId}) if (defined $self->{Source}{SystemId}); return { @properties }; }

Replies are listed 'Best First'.
Re^2: XML-Parser-PerlSAX how to get the BytePosition value
by Anonymous Monk on Apr 01, 2008 at 14:23 UTC

    yes I saw that piece of code before posting the above message.
    in the listing number:

    1. Are there any internel hooks that can return the "BytePosition - The current byte position of the parse."

    what I meant is:

    What ever the data processing that I make is in call back routines. Where as the function XML::Parser::PerlSAX->location() is not a part of callback routine, instead it is a XML::Parser::PerlSAX built in function.

    AFIAK, I can't call this function (XML::Parser::PerlSAX->location) inside any of the call back routine. So only time I call this function is when I have finished parsing my entire XML doc. (correct me if I am wrong.)

      1. create sub start_document in your handler package. It can be empty.
      2. create sub set_document_locator.
      sub new { my $proto = shift; my $class = ref($proto) || $proto; my $self = {}; return bless $self, $class; } sub start_document { # Empty. But MUST exist. } sub set_document_locator { my ($self, $params) = @_; $self->{'_parser'} = $params->{'Locator'}; } sub start_element { my $self = shift; print Dumper($self->{'_parser'}->location()); }