Here you can find the source of getFirstTextChild(Node n)
Parameter | Description |
---|---|
n | a parameter |
public static Node getFirstTextChild(Node n)
//package com.java2s; /*// w w w . ja va2 s. c om This file is part of p300. p300 is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. p300 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 General Public License for more details. You should have received a copy of the GNU General Public License along with p300. If not, see <http://www.gnu.org/licenses/>. */ import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { /** * Return the first text child node of a given node * Returns null if there is no text child node * @param n * @return */ public static Node getFirstTextChild(Node n) { NodeList children = n.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node currentChild = children.item(i); if (children.item(i).getNodeType() == Node.TEXT_NODE) { return currentChild; } } return null; } /** * Return the first text child of a node that contains the given text * Returns null if no such child exists * @param n * @param text * @return */ public static Node getFirstTextChild(Node n, String text) { NodeList children = n.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node currentChild = children.item(i); String nodeValue = currentChild.getNodeValue(); if (nodeValue != null && nodeValue.equalsIgnoreCase(text)) { return currentChild; } } return null; } }