Here you can find the source of getText(Node node)
private static String getText(Node node)
//package com.java2s; /******************************************************************************* * Copyright (c) 2012 Firestar Software, Inc. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:/*from ww w .j a v a2 s .c o m*/ * Firestar Software, Inc. - initial API and implementation * * Author: * Gabriel Oancea * *******************************************************************************/ import org.w3c.dom.*; public class Main { private static String getText(Node node) { if (node == null) return null; NodeList lst = node.getChildNodes(); int size = lst.getLength(); StringBuffer sb = new StringBuffer(); for (int i = 0; i < size; i++) { Node n = lst.item(i); if (n.getNodeType() == Node.TEXT_NODE) { Text t = (Text) n; sb.append(t.getData()); } } return sb.toString(); } }