ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> perl-xml
perl-xml
Re: Question about getNodeName
by Petr Pajas other posts by this author
Jun 13 2006 2:05PM messages near this date
view in the new Beta List Site
RE: Question about getNodeName | Re: Question about getNodeName
& XSLT On Tuesday 13 June 2006 20:26, Mesdaq, Ali wrote:

Hi,

>  When using DOM

I assume you mean XML::DOM?

>  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::DOM 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@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Thread:
Ali Mesdaq
Mark - BLS CTR Thomas
Petr Pajas
Bjoern Hoehrmann

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved