Java tutorial
//package com.java2s; /** * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE, version 2.1, dated February 1999. * * This program is free software; you can redistribute it and/or modify * it under the terms of the latest version of the GNU Lesser General * Public License as published by the Free Software Foundation; * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program (LICENSE.txt); if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ import org.w3c.dom.Node; public class Main { /** * Get XML <code>Node</code> text content. This method duplicates the * org.w3c.dom.Node.getTextContent() method in JDK 1.5. * * @param baseNode The XML node from which the content is being retrieved. * @return The text content of the XML node. */ public static String getTextContent(Node baseNode) { // if element, first child will be a text element with content Node child = baseNode.getFirstChild(); if (child != null && child.getNodeType() == Node.TEXT_NODE) { return child.getNodeValue(); } return ""; } }