Here you can find the source of getTextData(Node node)
public static String getTextData(Node node)
//package com.java2s; //License from project: Apache License import org.w3c.dom.CDATASection; import org.w3c.dom.Node; import org.w3c.dom.Text; public class Main { public static String getTextData(Node node) { if (!node.hasChildNodes()) { return null; }/* w ww . j av a 2 s . c o m*/ Node child = node.getFirstChild(); while (child != null && child.getNodeType() != Node.TEXT_NODE && child.getNodeType() != Node.CDATA_SECTION_NODE) { child = child.getNextSibling(); } if (child == null) { return null; } if (child.getNodeType() == Node.TEXT_NODE) { return ((Text) child).getData(); } else { return ((CDATASection) child).getData(); } } }