Here you can find the source of getTextContent(final Node node)
public static String getTextContent(final Node node)
//package com.java2s; //License from project: Apache License import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { public static String getTextContent(final Node node) { boolean hasTextContent = false; final StringBuffer buffer = new StringBuffer(); final NodeList nlist = node.getChildNodes(); for (int i = 0; i < nlist.getLength(); i++) { final Node child = nlist.item(i); if (child.getNodeType() == Node.TEXT_NODE) { buffer.append(child.getNodeValue()); hasTextContent = true;//from w ww .j av a 2s. c o m } } return hasTextContent ? buffer.toString() : null; } }