Subject: | Without the Handler, wrong nodes are selected. |
With no Handler specified, wrong nodes are processed as shown in 1.pl. The output should be the same for both iterations of the loop.
Patch attached: unbindNode must be called even if there's no Handler.
Subject: | 1.pl |
#!/usr/bin/perl
use warnings;
use strict;
use XML::LibXML::SAX;
use XML::Filter::DOMFilter::LibXML;
use XML::SAX::Writer;
my $input = '<r> <z/> <a/> <b/> <a/> <c/> <d/> </r>';
for my $handler (1, 0) {
print "---\n";
my $parser ='XML::LibXML::SAX'
->new( Handler =>
'XML::Filter::DOMFilter::LibXML'
->new($handler ? ( Handler => 'XML::SAX::Writer::XML'
->new(
Output => '/dev/null',
Writer => 'XML::SAX::Writer::XML'
)) : (),
Process => [ map { $_->[0] => [ sub { shift->(shift) },
$_->[1], $input] }
[ 'a', sub { warn ++$%, shift } ]
]
));
$parser->parse_string($input);
}
Subject: | xml.patch |
--- XML/Filter/DOMFilter/LibXML.pm~ 2003-09-12 12:16:17.000000000 +0200
+++ XML/Filter/DOMFilter/LibXML.pm 2015-11-03 14:28:50.943552502 +0100
@@ -135,12 +135,10 @@
# simple callback
&{$self->{Matched}}($node);
}
- if ($self->{Handler}) {
- my $process=XML::LibXML::SAX::Parser->new(Handler => $self->{Handler});
- foreach my $n ($parent->childNodes) {
- $process->process_node($n);
+ my $process=XML::LibXML::SAX::Parser->new(Handler => $self->{Handler});
+ foreach my $n ($parent->childNodes) {
+ $process->process_node($n) if $self->{Handler};
$n->unbindNode();
- }
}
}
}