On Friday 12 July 2002 11:44, you wrote:
> hallo ronald, hi matt,
>
> On Thu, Jul 11, 2002 at 06:06:28PM +0100, Matt Sergeant wrote:
> > Ronald - forwarding to [EMAIL PROTECTED] where this module is
> > discussed (and I'm not the developer any more).
> >
> > --
> > <!-- Matt -->
> > <:->Get a smart net</:->
> >
> > ---------- Forwarded message ----------
> > Date: Thu, 11 Jul 2002 18:59:52 +0200
> > From: Ronald Bach <[EMAIL PROTECTED]>
> > To: Matt Sergeant <[EMAIL PROTECTED]>
> > Subject: I'm not sure: Bug? XML::LibXML
> >
> > Hi Matt,
> >
> > I try to determine if a node in a dom tree has children or not.
> >
> > Problem: The script say for the empty tag "alternativ": Has children -
> > but don't print any child.
> > If I insert a whitespace into the tag "alternativ" the script say: Has no
> > child!
> > Is this a bug????
>
> no, it's not a bug. XML::LibXML works entirely correctly there. :)
> your test if a node has child nodes is too limited.
>
Hallo Christian,
thank you for your answer!
> first, use hasChildNodes() to find out if a node has childnodes. This
> much faster than the childNodes() + array test (about 10*$#childnodes)
> this function is specified in DOM and there this function is named
> explicitly for such tests.
That is what I want!
I need all tags which contain datas (or are empty) and have no other tags
included.
But I think every node has child: a text node.
Because the test say this:
-snip-
#if ($#children <= 0){#No Children
if (! $node->hasChildNodes){
print $node->nodeName," has no child\n";
#so I try to get the value of a tag.......
print $node->firstChild->getData, " =Data\n";
}
else{
print $node->nodeName," has Children----\n";
foreach my $item ($node->getChildNodes){
print "Child: ",$item->nodeName,"\n";
}
}
-snip-
...and for the test it's not the same when I write <alternativ></alternativ>
or <alternativ> </alternativ> (content=whitespace).
....Sorry for my "stupid" test script and all inconvenience!
Ron
>
> second - and there is a bug in your code: an perl array has elements if
> the number of items is GREATER than zero (0). because of that scalar()
> returns two different states depending on the state of the array variable.
>
> so scalar() returns -1 if the array itself is not defined. it returns
> 0 if the array was defined but contains no elements. so your condition
> has to be
>
> if ( $#myarray > 0 ) { ... }
>
> to work correct.
>
> christian
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]