Results 1 to 5 of 5
  1. #1
    farm is offline Member
    Join Date
    Feb 2009
    Posts
    2
    Rep Power
    0

    Default Returning the text content of the current node only

    How can I return the text contents of a XML node but excluding the text contents of its descendants.

    If I use the method node.getTextContent(), it will return the text contents for the current node and all its descendants.

    Any Idea!!

  2. #2
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    6

  3. #3
    farm is offline Member
    Join Date
    Feb 2009
    Posts
    2
    Rep Power
    0

    Default It worked

    Yes it has worked, this is my final code which prints the text value of leaf nodes:

    treeNodeLabel = childElement.getNodeName();
    if (childElement.hasChildNodes())
    if (!childElement.getFirstChild().getNodeValue().trim ().isEmpty()){
    treeNodeLabel = childElement.getNodeName() + " = " + childElement.getFirstChild().getNodeValue();
    }

  4. #4
    Join Date
    Jan 2009
    Location
    Delhi
    Posts
    8
    Rep Power
    0

    Default

    OR even u can try this also

    "String childNodeValue = childNode.getChildNodes().item(0)
    .getTextContent();"

    It does return the value of the first node u r trying to get......

  5. #5
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    6

Similar Threads

  1. Replies: 7
    Last Post: 08-17-2010, 07:00 PM
  2. Replies: 10
    Last Post: 05-24-2010, 09:25 PM
  3. java DOM: append text to node
    By newbieal in forum New To Java
    Replies: 2
    Last Post: 10-10-2008, 08:18 PM
  4. Replies: 5
    Last Post: 07-18-2008, 05:30 PM
  5. Replies: 0
    Last Post: 05-26-2008, 05:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •