Java tutorial
//package com.java2s; /* // This software is subject to the terms of the Eclipse Public License v1.0 // Agreement, available at the following URL: // http://www.eclipse.org/legal/epl-v10.html. // You must accept the terms of that agreement to use this software. // // Copyright (C) 2003-2005 Julian Hyde // Copyright (C) 2005-2011 Pentaho // Copyright (c) 2008-2014 Open Link Financial, Inc. All Rights Reserved. */ import org.w3c.dom.*; import java.util.*; public class Main { public static String textInElement(Element elem) { StringBuilder buf = new StringBuilder(100); elem.normalize(); NodeList nlst = elem.getChildNodes(); for (int i = 0, nlen = nlst.getLength(); i < nlen; i++) { Node n = nlst.item(i); if (n instanceof Text) { final String data = ((Text) n).getData(); buf.append(data); } } return buf.toString(); } private static <T> String toString(List<T> list) { StringBuilder buf = new StringBuilder(); int k = -1; for (T t : list) { if (++k > 0) { buf.append(", "); } buf.append(t); } return buf.toString(); } }