Java tutorial
//package com.java2s; import org.w3c.dom.Node; public class Main { public static String getNodeText(Node node) { if (node == null) return null; StringBuffer buff = new StringBuffer(); for (int c = 0; c < node.getChildNodes().getLength(); c++) { Node cn = node.getChildNodes().item(c); if (cn.getNodeType() == Node.TEXT_NODE || cn.getNodeType() == Node.CDATA_SECTION_NODE) { buff.append(cn.getNodeValue()); } } return buff.toString().trim(); } }