Here you can find the source of getChildText(final Node node)
Parameter | Description |
---|---|
node | The node to look at. |
public static String getChildText(final Node node)
//package com.java2s; /*/*from w w w . jav a 2s . c om*/ * JBoss, Home of Professional Open Source. * * See the LEGAL.txt file distributed with this work for information regarding copyright ownership and licensing. * * See the AUTHORS.txt file distributed with this work for a full listing of individual contributors. */ import org.w3c.dom.Node; public class Main { /** * Returns the concatenated child text of the specified node. This method only looks at the immediate children of type * <code>Node.TEXT_NODE</code> or the children of any child node that is of type <code>Node.CDATA_SECTION_NODE</code> for the * concatenation. This method was copied from the org.apache.xerces.util.DOMUtil class. * * @param node The node to look at. */ public static String getChildText(final Node node) { // is there anything to do? if (node == null) { return null; } // concatenate children text StringBuffer str = new StringBuffer(); Node child = node.getFirstChild(); while (child != null) { short type = child.getNodeType(); if (type == Node.TEXT_NODE) { str.append(child.getNodeValue()); } else if (type == Node.CDATA_SECTION_NODE) { str.append(getChildText(child)); } child = child.getNextSibling(); } // return text value return str.toString(); } }