Here you can find the source of getText(Node n)
Parameter | Description |
---|---|
n | the node to look for text on |
public static String getText(Node n)
//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(); } }