Here you can find the source of getChildText(final Node node)
public static String getChildText(final Node node)
//package com.java2s; //License from project: Apache License import org.w3c.dom.Node; public class Main { public static String getChildText(final Node node) { if (node == null) { return null; } else {// w ww. j ava2 s . c o m final StringBuilder text = new StringBuilder(); appendChildText(text, node); return text.toString(); } } public static void appendChildText(final StringBuilder text, final Node node) { if (node != null) { for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) { final short type = child.getNodeType(); if (type == Node.TEXT_NODE) { final String childText = child.getNodeValue(); text.append(childText); } else if (type == Node.CDATA_SECTION_NODE) { appendChildText(text, child); } } } } }