Here you can find the source of getTextContent(Node n)
public static String getTextContent(Node n)
//package com.java2s; import org.w3c.dom.*; public class Main { public static String getTextContent(Node n) { StringBuffer buffer = new StringBuffer(); NodeList childList = n.getChildNodes(); Node child;/*w w w . j ava 2 s . c om*/ short nodetype; for (int i = 0; i < childList.getLength(); i++) { child = childList.item(i); nodetype = child.getNodeType(); if (nodetype != Node.TEXT_NODE && nodetype != Node.CDATA_SECTION_NODE) continue; buffer.append(child.getNodeValue()); } return buffer.toString(); } }