Java tutorial
//package com.java2s; /* infoScoop OpenSource * Copyright (C) 2010 Beacon IT Inc. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License version 3 * 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. If not, see * <http://www.gnu.org/licenses/lgpl-3.0-standalone.html>. */ import org.w3c.dom.Node; public class Main { /** * We get a object that connected text node of the child node and the CDATA section as character string. * @param node * @return */ public static String getChildText(Node node) { StringBuffer buf = new StringBuffer(); for (int i = 0; i < node.getChildNodes().getLength(); i++) { Node n = node.getChildNodes().item(i); if (n.getNodeType() == Node.TEXT_NODE || n.getNodeType() == Node.CDATA_SECTION_NODE) { buf.append(n.getNodeValue()); } } return buf.toString(); } }