Java XML First Child Element getFirstTextChild(Node node)

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

Description

get First Text Child

License

Open Source License

Declaration

public static String getFirstTextChild(Node node) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    public static String getFirstTextChild(Node node) {
        NodeList nodeList = node.getChildNodes();
        if (nodeList != null) {
            for (int index = 0; index < nodeList.getLength(); index++) {
                Node child = nodeList.item(index);
                if (child.getNodeType() == Node.TEXT_NODE) {
                    if (child.getNodeValue() != null && child.getNodeValue().trim().length() > 0) {
                        return child.getNodeValue();
                    }/*from   ww w  . j a  v a2 s  .  com*/
                }
            }
        }
        return null;
    }
}

Related

  1. getFirstNamedChildNode(Element element, String string)
  2. getFirstNamedChildNode(Node root, String nodeName)
  3. getFirstNontextChild(Node d)
  4. getFirstNonTextChild(Node root)
  5. getFirstTextChild(Node n)
  6. getFirstVisibleChildElement(Node parent)
  7. getValueOfFirstElementChild(final Element element, final String namespace, final String localname)
  8. insertBeforeFirstChild(Element object, Element attrId)
  9. readFirstChild(Node parentNode, String nodeName)