Here you can find the source of getNodeText(Node node)
public static String getNodeText(Node node)
//package com.java2s; /******************************************************************************* * Copyright (c) 2007 Chase Technology Ltd - http://www.chasetechnology.co.uk * 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 w w w.j a v a 2 s.c o m*/ * Doug Satchwell (Chase Technology Ltd) - initial API and implementation *******************************************************************************/ import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { public static String getNodeText(Node node) { switch (node.getNodeType()) { case Node.ELEMENT_NODE: NodeList childNodes = node.getChildNodes(); StringBuffer sb = new StringBuffer(); for (int i = 0; i < childNodes.getLength(); i++) { Node child = childNodes.item(i); if (child.getNodeType() == Node.TEXT_NODE) { sb.append(child.getNodeValue()); } } return sb.toString(); case Node.TEXT_NODE: case Node.ATTRIBUTE_NODE: default: return node.getNodeValue(); } } }