Java XML First Child Element getFirstChildTextNodeValue(Node node)

Here you can find the source of getFirstChildTextNodeValue(Node node)

Description

Returns value of first available child text node or null if not found.

License

Open Source License

Declaration

public static String getFirstChildTextNodeValue(Node node) 

Method Source Code

//package com.java2s;
/**//w w  w.  j  a  v  a2 s . co  m
 * This file is part of SIMPL4(http://simpl4.org).
 *
 *    Copyright [2014] [Manfred Sattler] <manfred@ms123.org>
 *
 * SIMPL4 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.
 *
 * SIMPL4 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 SIMPL4.  If not, see <http://www.gnu.org/licenses/>.
 */

import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Main {
    /**
     * Returns value of first available child text node or <code>null</code> if not found.
     */
    public static String getFirstChildTextNodeValue(Node node) {
        NodeList children = node.getChildNodes();
        int len = children.getLength();
        for (int i = 0; i < len; i++) {
            Node n = children.item(i);
            if (n.getNodeType() == Node.TEXT_NODE) {
                return n.getNodeValue();
            }
        }
        return null;
    }
}

Related

  1. getFirstChildText(@Nullable final Node aStartNode)
  2. getFirstChildText(Node aNode)
  3. getFirstChildText(Node parent)
  4. getFirstChildTextByTagName(Element element, String tagName)
  5. getFirstChildTextContent(Node node)
  6. getFirstChildTextValue(Element parent, String childName)
  7. getFirstChildWithTagName(Element parent, String tagName)
  8. getFirstChildWithTagName(Node data, String tagName)
  9. getFirstElement(Element element, String childName)