Java tutorial
//package com.java2s; /******************************************************************************* * Copyright (c) 2004-2010 IBM Corporation. * 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: * IBM Corporation - initial API and implementation *******************************************************************************/ import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { /** * (A useful utility method from IBM developerworks) */ public static String getTextContents(Node node) { NodeList childNodes; StringBuffer contents = new StringBuffer(); childNodes = node.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { if (childNodes.item(i).getNodeType() == Node.TEXT_NODE) { contents.append(childNodes.item(i).getNodeValue()); } } return contents.toString(); } }