Java XML Node Parent getFirstValidNode(Node node)

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

Description

get First Valid Node

License

Apache License

Declaration

public static Node getFirstValidNode(Node node) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

public class Main {
    public static Node getFirstValidNode(Node node) {
        NodeList children = node.getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            if (isValidNode(children.item(i)))
                return children.item(i);
        }/*from w  w  w.  j a  va  2s .  com*/

        return null;
    }

    public static boolean isValidNode(Node node) {
        return !node.getNodeName().equals("#text");
    }

    public static boolean isValidNode(Node node, String name) {
        return node.getNodeName().equals(name);
    }
}

Related

  1. getFirstElementByTagName(Node node, String tagName)
  2. getFirstElementByTagName(Node node, String tagName)
  3. getFirstElementWithTagName(Node node, String element)
  4. getFirstNamedNode(Node node, String name)
  5. getFirstNodeByName(Node root, String tagName)
  6. getParent(Element elem)
  7. getParent(Element elem)
  8. getParent(final Node n)
  9. getParent(Node node)