Here you can find the source of getText(Node node)
public static String getText(Node node)
//package com.java2s; /******************************************************************************* * Copyright (c) 2006-2010 eBay Inc. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 *******************************************************************************/ import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { public static String getText(Node node) { StringBuffer result = new StringBuffer(); NodeList nodes = node.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { Node node2 = nodes.item(i); if (node2.getNodeType() == Node.TEXT_NODE || node2.getNodeType() == Node.CDATA_SECTION_NODE) { String value = node2.getNodeValue(); result.append(value);//from w w w. j a va2 s . c o m } } return result.toString().trim(); } }