Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   Text nodes and element nodes query (http://www.velocityreviews.com/forums/t143695-text-nodes-and-element-nodes-query.html)

asd 05-23-2005 07:29 AM

Text nodes and element nodes query
 
Hi all,

The code below gets me a list of all the nodes within the node object
called xml_tags_root.

NodeList nl = xml_tags_root.getChildNodes();

The length of nodelist I get is double the number of actual elements!
This is because after every element node there is text node which is (I
think) the whitespace in the XML document.

Is there a way to get only the element nodes?

Please advice.

thanks,
ASD


Arnaud Berger 05-23-2005 07:35 AM

Re: Text nodes and element nodes query
 
Hi,

Look at getElementsByTagName(....)

Regards,

Arnaud

"asd" <arvindsd@yahoo.com> a écrit dans le message news:
1116833345.887839.95270@g47g2000cwa.googlegroups.c om...
> Hi all,
>
> The code below gets me a list of all the nodes within the node object
> called xml_tags_root.
>
> NodeList nl = xml_tags_root.getChildNodes();
>
> The length of nodelist I get is double the number of actual elements!
> This is because after every element node there is text node which is (I
> think) the whitespace in the XML document.
>
> Is there a way to get only the element nodes?
>
> Please advice.
>
> thanks,
> ASD
>




asd 05-23-2005 09:15 AM

Re: Text nodes and element nodes query
 
Thanks for your reply.

Can I get a nodelist which consists of only Element Nodes but no text
nodes out of all the child elements of a node?

getElementsByTagname() will be used when one is aware of the name of
the tag in advance, right?

regards,

asd


Arnaud Berger 05-23-2005 10:01 AM

Re: Text nodes and element nodes query
 
Hi,

See getNodeType() in class org.w3c.dom.Node, and various possible static
values :

e.g Node.ELEMENT_NODE, Node.TEXT_NODE ....

Regards,

Arnaud


"asd" <arvindsd@yahoo.com> a écrit dans le message news:
1116839706.525280.13080@f14g2000cwb.googlegroups.c om...
> Thanks for your reply.
>
> Can I get a nodelist which consists of only Element Nodes but no text
> nodes out of all the child elements of a node?
>
> getElementsByTagname() will be used when one is aware of the name of
> the tag in advance, right?
>
> regards,
>
> asd
>





All times are GMT. The time now is 06:52 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.