XML::LibXML::SAX question
Atanas Karashenski <[email protected]>
| Newsgroups | gmane.comp.lang.perl.xml |
|---|---|
| Message-ID | <[email protected]> |
HI, As my colleague Sava states here it seems that XML::LibXML::SAX has a bug. http://aspn.activestate.com/ASPN/Mail/Message/perl-xml/1897428 I applied the attached patch - a slightly modified version of proposed from Sava patch and the following test script works with the patch and doesn't work without the patch. Is there something wrong in the way I use parse_chunk() or the module really needs the patch? Environment: ------------------- openSuSE 11.0 perl-5.10.0 libxml2-2.6.32-11.1 XML-LibXML-1.66 Test script --------------- #!/usr/bin/perl use XML::LibXML::SAX; use XML::LibXML::SAX::Builder; my ($parser, $builder, $chunk); $chunk = '<ce><service><app>LOGOUT</app><ctrl>LOGOUT</ctrl></service></ce>'; $builder = XML::LibXML::SAX::Builder->new( Encoding => 'UTF-8' ); $builder->start_document(); $parser = XML::LibXML::SAX->new( Handler => $builder ); $parser->parse_chunk($chunk); $builder->end_document(); print $builder->result()->toString(); ----------------- End of script Best regards, Atanas Karashenski BlueBoard LLC _______________________________________________ Perl-XML mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
XML-LibXML-SAX-parse_chunk.patch
(text/x-patch, 1.5 KB)
--- lib/XML/LibXML/SAX.pm 2003-08-20 00:06:31.000000000 +0300
+++ lib/XML/LibXML/SAX.pm-patched 2003-11-24 17:36:09.000000000 +0200
@@ -27,7 +27,8 @@
$self->{ParserOptions}{LibParser} = XML::LibXML->new;
$self->{ParserOptions}{ParseFunc} = \&XML::LibXML::parse_fh;
$self->{ParserOptions}{ParseFuncParam} = $fh;
- return $self->_parse;
+ $self->_parse;
+ return $self->end_document({});
}
sub _parse_string {
@@ -36,7 +37,8 @@
$self->{ParserOptions}{LibParser} = XML::LibXML->new() unless defined $self->{ParserOptions}{LibParser};
$self->{ParserOptions}{ParseFunc} = \&XML::LibXML::parse_string;
$self->{ParserOptions}{ParseFuncParam} = $string;
- return $self->_parse;
+ $self->_parse;
+ return $self->end_document({});
}
sub _parse_systemid {
@@ -44,12 +46,14 @@
$self->{ParserOptions}{LibParser} = XML::LibXML->new;
$self->{ParserOptions}{ParseFunc} = \&XML::LibXML::parse_file;
$self->{ParserOptions}{ParseFuncParam} = shift;
- return $self->_parse;
+ $self->_parse;
+ return $self->end_document({});
}
sub parse_chunk {
my ( $self, $chunk ) = @_;
$self->{ParserOptions}{LibParser} = XML::LibXML->new;
+ $self->{ParserOptions}{LibParser}->{IS_FILTER} = 1; #xxx hack
$self->{ParserOptions}{ParseFunc} = \&XML::LibXML::parse_xml_chunk;
$self->{ParserOptions}{ParseFuncParam} = $chunk;
return $self->_parse;
@@ -73,7 +77,6 @@
if ( $@ ) {
croak $@;
}
- return $self->end_document({});
}