Text nodes and element nodes query

Discussion in 'Java' started by asd, May 23, 2005.

  1. asd

    asd Guest

    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, May 23, 2005
    #1
    1. Advertising

  2. Hi,

    Look at getElementsByTagName(....)

    Regards,

    Arnaud

    "asd" <> a écrit dans le message news:
    ...
    > 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, May 23, 2005
    #2
    1. Advertising

  3. asd

    asd Guest

    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
    asd, May 23, 2005
    #3
  4. 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" <> a écrit dans le message news:
    ...
    > 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, May 23, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Xamle Eng

    Why treat text nodes as nodes?

    Xamle Eng, May 13, 2005, in forum: XML
    Replies:
    8
    Views:
    476
    Fredrik Lundh
    May 28, 2005
  2. Replies:
    2
    Views:
    400
    Martin Honnen
    May 23, 2005
  3. Replies:
    0
    Views:
    471
  4. HANM
    Replies:
    2
    Views:
    682
    Joseph Kesselman
    Jan 29, 2008
  5. Volker Lenhardt
    Replies:
    4
    Views:
    988
    Volker Lenhardt
    Feb 23, 2012
Loading...

Share This Page