On Tuesday 13 June 2006 20:26, Mesdaq, Ali wrote:
Hi,
> When using DOM
I assume you mean XML: OM?
> and getNodeName I get the name and "#text"
returned. Why
> is #text returned
It's because you *are* indeed accessing a text node, not a
subelement (which
is what you seem to expect). Unlike elements, text nodes do
not have names,
that is why this method of XML: OM
returns '#text' instead. Note that
white-space also produces text nodes.
> and how can I have only the name returned?
You didn't indicate how your XML instance looks like. But
assuming it looks
something like
<doc>
<foo>...</foo>
</doc>
(e.g doc has - at least - 3 child nodes: a blank text node,
element foo, and
another blank text node with the newline following
</foo>)
you can either use $root->getElementByTagName('foo',0),
or check the node type
of each child node (e.g. with $kid->isElementNode or
$kid->getNodeType ==
ELEMENT_NODE) skipping non-element nodes where appropriate.
> my $root = $doc->getDocumentElement();
> my installinfo = $root->getChildNodes();
> foreach my $run ( installinfo)
> {
> print $run->getNodeName(),
"\n";
> }
-- Petr
_______________________________________________
Perl-XML mailing list
Perl-XML listserv.ActiveState.com
To unsubscribe: http:/
/listserv.ActiveState.com/mailman/mysubs
|