Here you can find the source of getTextForNode(Node node)
Parameter | Description |
---|---|
node | the node of interest |
public static String getTextForNode(Node node)
//package com.java2s; //License from project: Open Source License import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { /**/*from ww w.ja va2 s . c o m*/ * Gets the String value of the node. If the node does not contain text then an empty String is returned * @param node the node of interest * @return the value of that node */ public static String getTextForNode(Node node) { NodeList children = node.getChildNodes(); if (children == null) { return ""; } for (int i = 0; i < children.getLength(); i++) { Node childNode = children.item(i); if ((childNode.getNodeType() == Node.TEXT_NODE) || (childNode.getNodeType() == Node.CDATA_SECTION_NODE)) { return childNode.getNodeValue(); } } return ""; } }