f



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

0
arvindsd (43)
5/23/2005 7:29:05 AM
comp.lang.java.programmer 52714 articles. 1 followers. Post Follow

3 Replies
467 Views

Similar Articles

[PageSpeed] 11

Hi,

Look at getElementsByTagName(....)

Regards,

Arnaud

"asd" <arvindsd@yahoo.com> a �crit dans le message news:
1116833345.887839.95270@g47g2000cwa.googlegroups.com...
> 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
>


0
a.berger (141)
5/23/2005 7:35:11 AM
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

0
arvindsd (43)
5/23/2005 9:15:06 AM
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.com...
> 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
>


0
a.berger (141)
5/23/2005 10:01:09 AM
Reply: