You are viewing a plain text version of this content. The canonical link for it is here.
Posted to p-dev@xerces.apache.org by Ryan Dewell <rd...@regnow.com> on 2002/02/11 23:24:02 UTC
TEXT_NODE's Contain One Child
Hello,
I'm using XML::Xerces v1.6 on Solaris 2.6. I've found that when calling
"getChildNodes" on a TEXT_NODE, the array which is returned contains a
single, zero length string. The more appropriate behavior would be to
return a zero element array, as text nodes do not have children.
I've included source which demonstrates this problem -- pass it a file as
the first parameter.
Regards,
Ryan Dewell
-------------------------
#!/usr/local/bin/perl
use strict;
use XML::Xerces;
my $file = $ARGV[0];
my $parser = XML::Xerces::IDOMParser->new();
eval {
$parser->parse (XML::Xerces::LocalFileInputSource->new($file));
};
if ($@) {
if (ref $@) {
die $@->getMessage();
} else {
die $@;
}
} else {
foreach my $node
($parser->getDocument->getDocumentElement->getChildNodes){
if ($node->getNodeName eq '#text'){
my @children = $node->getChildNodes();
print "Child Count: " . scalar(@children) . "\n";
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-p-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-p-dev-help@xml.apache.org
Re: TEXT_NODE's Contain One Child
Posted by "Jason E. Stewart" <ja...@openinformatics.com>.
"Jason E. Stewart" <ja...@openinformatics.com> writes:
> "Ryan Dewell" <rd...@regnow.com> writes:
>
> > I'm using XML::Xerces v1.6 on Solaris 2.6. I've found that when
> > calling "getChildNodes" on a TEXT_NODE, the array which is returned
> > contains a single, zero length string. The more appropriate
> > behavior would be to return a zero element array, as text nodes do
> > not have children.
In XML::Xerces-1.7 I'm not able to reproduce this:
DB<10> x $node_list[5]->getChildNodes->item(0)
0 XML::Xerces::DOM_Text=HASH(0x1060b060)
empty hash
DB<11> x $node_list[5]->getChildNodes->item(0)->getChildNodes
empty array
It appears that the problem has been fixed in Xerces-C.
jas.
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-p-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-p-dev-help@xml.apache.org
Re: TEXT_NODE's Contain One Child
Posted by "Jason E. Stewart" <ja...@openinformatics.com>.
"Ryan Dewell" <rd...@regnow.com> writes:
> I'm using XML::Xerces v1.6 on Solaris 2.6. I've found that when
> calling "getChildNodes" on a TEXT_NODE, the array which is returned
> contains a single, zero length string. The more appropriate
> behavior would be to return a zero element array, as text nodes do
> not have children.
Actually what is happening, is that it is returning undef which you
are assigning to the first element of the list.
Here's the code:
sub getChildNodes {
my @args = @_;
my $result = XML::Xercesc::IDOM_Node_getChildNodes(@args);
return undef if (!defined($result));
return $result->to_list() if wantarray;
$IDOM_NodeList::OWNER{$result} = 1;
my %resulthash;
tie %resulthash, ref($result), $result;
return bless \%resulthash, ref($result);
}
for some (unknown) reason, XML::Xercesc::IDOM_Node_getChildNodes() -
the internal C++ method - is returning undef, and so that is what
get's returned by the Perl wrapper method.
I don't know why it's returning undef, which is one problem, but in
anycase it should be returning an empty list, and not undef.
Thanks for finding this bug, too,
jas.
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-p-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-p-dev-help@xml.apache.org