Here you can find the source of getText(Node n)
public synchronized static String getText(Node n)
//package com.java2s; import org.w3c.dom.*; public class Main { /**/*from w ww. j a v a2 s.c o m*/ * Gets the text for a node by concatenating child TEXT elements. */ public synchronized static String getText(Node n) { if (n == null) throw new IllegalArgumentException("Node argument cannot be null"); StringBuilder b = new StringBuilder(); NodeList nl = n.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { if (nl.item(i).getNodeType() == Node.TEXT_NODE) b.append(nl.item(i).getNodeValue()); else if (nl.item(i).getNodeType() == Node.CDATA_SECTION_NODE) b.append(nl.item(i).getNodeValue()); } return b.toString().trim(); } }