Skip Menu |
 

This queue is for tickets about the XML-LibXML CPAN distribution.

Report information
The Basics
Id: 91433
Status: resolved
Priority: 0/
Queue: XML-LibXML

People
Owner: Nobody in particular
Requestors: ThB [...] gymel.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in:
  • 2.0019
  • 2.0107
Fixed in: (no value)



Subject: Typo in Builder.pm
Download (untitled) / with headers
text/plain 436b
start_element on a root element gives annoying warnings for uninitialized variables in LibXML.pm at the calls of _setNamespace in setNamespace() method for XML::LibXML::Element. Turns out to be a Typo in LibXML::SAX::Builder.pm, line 191: The attribute's name has to be 'LocalName' instead of 'Localname'. BTW the generator in question, which by the comment two lines above "does not set namespaces correctly" is XML::LibXML::SAX ...
Download (untitled) / with headers
text/plain 684b
Hi THB, On Sun Dec 15 13:13:48 2013, THB wrote: Show quoted text
> start_element on a root element gives annoying warnings for > uninitialized variables in LibXML.pm at the calls of _setNamespace in > setNamespace() method for XML::LibXML::Element. > > Turns out to be a Typo in LibXML::SAX::Builder.pm, line 191: The > attribute's name has to be 'LocalName' instead of 'Localname'. > > BTW the generator in question, which by the comment two lines above > "does not set namespaces correctly" is XML::LibXML::SAX ...
It's hard to understand from your description how to reproduce this bug. Can you provide a reproducing script or more preferably a test script that fails? Regards, -- Shlomi Fish
Download (untitled) / with headers
text/plain 284b
Show quoted text
> It's hard to understand from your description how to reproduce this > bug. Can you provide a reproducing script or more preferably a test > script that fails?
Not easily. But ain't the typo obvious if you look at < http://perl-xml.sourceforge.net/perl-sax/sax-2.1.html >? Thomas
Download (untitled) / with headers
text/plain 644b
Hello Thomas, On Sun Dec 15 18:41:23 2013, THB wrote: Show quoted text
>
> > It's hard to understand from your description how to reproduce this > > bug. Can you provide a reproducing script or more preferably a test > > script that fails?
> > Not easily. But ain't the typo obvious if you look at < http://perl- > xml.sourceforge.net/perl-sax/sax-2.1.html >?
Please provide such a test script, regardless of how "not easily" it would be (and it shouln't be too hard because $SIG{__WARN__} can trap warnings. By policy, I don't fix bugs in XML::LibXML without an accompanying test, whenever possible. Sorry if I'm sounding harsh. Regards, -- Shlomi Fish
All right, attached test data (test.rdf) and a script (testcase.pl) reproducing the warnings: An OAI response (processed by the outerSAX handler in the script) may contain one or several OAI:records . Within each record there es an metadata element still in the OAI namespace. Inside this metadata container there is exactly one element belonging to an arbitrary foreign namespace and the subtree it spans shall be captured with an XML::LibXML::SAX::Builder (in order to process it with LibXSLT - not relevant for the test case). Therefore the outerSAX handler activates the innerSAX handler for bookkeeping which in turn instantiates a fresh Builder whenever it finds itself on the outmost level. Now each Namespace attribute of the element directly below the OAI:metadata element (i.e. the root node of the document to be constructed) provoces one warning in LibXML.pm, because the namespace prefixes provided to setNamespace() by start_element() in Builder.pm are erroneously undef due to the typo in line 191. Hope this helps (and sorry if I didn't catch your remark with respect to $SIG{__WARN__}) Thomas
Subject: test.rdf
Download test.rdf
application/rdf+xml 2.2k

Message body not shown because it is not plain text.

Subject: testcase.pl
Download testcase.pl
text/x-perl 2.5k
#!/usr/bin/perl -w use strict; use warnings; BEGIN { $XML::SAX::ParserPackage = "XML::LibXML::SAX"; } use XML::SAX::ParserFactory; my $metadataHandler = innerSAX->new(); my $oaiHandler = outerSAX->new(metadataHandler => $metadataHandler, oaiNS => "http://www.openarchives.org/OAI/2.0/"); my $parser = XML::SAX::ParserFactory->parser(Handler => $oaiHandler); $parser->parse_file("test.rdf"); package outerSAX; use base qw(XML::SAX::Base); sub new { my ($class, %opts) = @_; my $self = bless \%opts, ref($class) || $class; $self->set_handler( undef ); return $self; } sub start_element { my ($self, $element) = @_; return $self->SUPER::start_element($element) unless $element->{NamespaceURI} eq $self->{oaiNS}; if ( $element->{LocalName} eq 'metadata' ) { $self->{ OLD_Handler } = $self->get_handler(); $self->set_handler( $self->{metadataHandler} ); } else { return $self->SUPER::start_element($element)}; } sub end_element { my ($self, $element) = @_; return $self->SUPER::end_element($element) unless $element->{NamespaceURI} eq $self->{oaiNS}; if ( $element->{LocalName} eq 'metadata' ) { $self->set_handler( $self->{OLD_Handler} ); } else { $self->SUPER::end_element($element); } } package innerSAX; use base qw(XML::SAX::Base); use XML::LibXML::SAX::Builder; sub new { my ($class, %opts) = @_; my $self = bless \%opts, ref($class) || $class; $self->{'tagStack'} = []; return $self; } sub start_element { my ($self, $element) = @_; unless ( $self->{'tagStack'}[0] ) { my $builder = XML::LibXML::SAX::Builder->new() or die "cannot instantiate SAX builder"; $self->set_handler($builder); $self->SUPER::start_document(); # i.e. $builder->start_document(); # DEBUG ME: warnings occur here $self->SUPER::start_element($element); } else { $self->SUPER::start_element($element)}; push(@{$self->{'tagStack'}}, $element->{Name}); } sub end_element { my ($self, $element) = @_; $self->SUPER::end_element($element); pop (@{$self->{'tagStack'}}); unless ( $self->{'tagStack'}[0] ) { my $hdl = $self->get_handler(); $self->set_handler(undef); # convert fragment to document, do something with it (in real life: XSLT) my $fragment = $hdl->done(); my $child = $fragment->firstChild(); $child = $child->nextSibling while $child && $child->nodeName eq "#text"; my $tempdoc = XML::LibXML::Document->createDocument() or die "cannot create new Document"; $tempdoc->addChild($child) or die "cannot addChild"; print $tempdoc->toString; } } 1;
Download (untitled) / with headers
text/plain 275b
Hi Thomas, thanks! I was able to convert your testcase into a working test file, and the fix with the test is now part of XML-LibXML-2.0108 which I just uploaded to CPAN. I'm closing this bug - please let me know if there's anything else you need. Regards, -- Shlomi Fish


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.