Here you can find the source of getTextContents(Element e)
public static String getTextContents(Element e)
//package com.java2s; // modify it under the terms of the GNU General Public License import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { public static String getTextContents(Element e) { if (!e.hasChildNodes()) return null; StringBuffer buf = new StringBuffer(); NodeList list = e.getChildNodes(); int len = list.getLength(); String text;/*from ww w . j av a 2 s. c o m*/ for (int i = 0; i < len; i++) { text = ((Node) list.item(i)).getNodeValue(); if (text != null) buf.append(text); } return buf.toString(); } }