Java XML Node Text Value getText(Node n)

Here you can find the source of getText(Node n)

Description

get Text

License

Open Source License

Parameter

Parameter Description
n the node to look for text on

Return

The conjoined values of all #text nodes immediately under this node

Declaration

public static String getText(Node n) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import org.w3c.dom.Node;

public class Main {
    /**/*from w w  w .  j a v  a2  s. com*/
     * @param n the node to look for text on
     * @return The conjoined values of all #text nodes immediately under this node 
     */
    public static String getText(Node n) {
        StringBuffer sb = new StringBuffer();
        for (Node ele = n.getFirstChild(); ele != null; ele = ele.getNextSibling()) {
            String name = ele.getNodeName();
            if (name.equalsIgnoreCase("#text"))
                sb.append(ele.getNodeValue());
        }
        return sb.toString().trim();
    }
}

Related

  1. getText(final Node node)
  2. getText(final Node xmlNode)
  3. getText(Node elem)
  4. getText(Node elem, StringBuilder buffer)
  5. getText(Node n)
  6. getText(Node n)
  7. getText(Node nd)
  8. getText(Node nd, StringBuilder buf)
  9. getText(Node node)