On Fri Feb 08 07:15:17 2008, habo wrote:
Show quoted text> according to the documentation, calling subroutine 'children' with
> argument "NAME" should return an array of all elements directly below
> the top-level that have the element name "NAME". Calling 'child' with
> argument "NAME" should return a single child element with name "NAME".
>
> It turned out that both methods don't just look up the elements
> "directly below the top-level" but perform a depth search on the
> sub-tree instead.
First off, I love this module. My thanks to the author for releasing it
and maintaining it over the years. Continued maintenance would be much
appreciated.
I recently came across this bug as well. Should the
getElementsByTagNameNS method calls be changed to getChildrenByTagNameNS
method calls in the child() and children() methods as well? I presume so
and have attached a updated patch.
--- LibXML.pm~ 2004-11-10 12:48:26.000000000 -0500
+++ LibXML.pm 2010-04-28 20:12:31.184068000 -0400
@@ -4,7 +4,7 @@
use XML::LibXML 1.53;
use XML::LibXML::Common;
-our $VERSION = '0.60';
+our $VERSION = '0.60.1';
sub attributes {
my $self = shift;
@@ -161,14 +161,14 @@
}
elsif ($self->hasNamespaces()) {
my ($namespaceURI, $localName) = $self->_parseTagName($tag, ELEMENT_NODE);
- my ($element) = $self->{_DOM}->getElementsByTagNameNS($namespaceURI, $localName);
+ my ($element) = $self->{_DOM}->getChildrenByTagNameNS($namespaceURI, $localName);
return unless ($element);
my $node = new XML::SimpleObject::LibXML ($element);
return $node;
}
else
{
- my ($element) = $self->{_DOM}->getElementsByTagName($tag);
+ my ($element) = $self->{_DOM}->getChildrenByTagName($tag);
return unless ($element);
my $node = new XML::SimpleObject::LibXML ($element);
return $node;
@@ -212,7 +212,7 @@
if ($self->hasNamespaces()) {
my ($namespaceURI, $localName) = $self->_parseTagName($tag, ELEMENT_NODE);
my @nodelist;
- foreach my $node ($self->{_DOM}->getElementsByTagNameNS($namespaceURI, $localName)) {
+ foreach my $node ($self->{_DOM}->getChildrenByTagNameNS($namespaceURI, $localName)) {
next if ($node->nodeType == TEXT_NODE);
push @nodelist, new XML::SimpleObject::LibXML ($node);
}
@@ -220,7 +220,7 @@
}
else {
my @nodelist;
- foreach my $node ($self->{_DOM}->getElementsByTagName($tag)) {
+ foreach my $node ($self->{_DOM}->getChildrenByTagName($tag)) {
next if ($node->nodeType == TEXT_NODE);
push @nodelist, new XML::SimpleObject::LibXML ($node);
}