Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Main {
    public static Node getFirstElementChild(Node parentNode) {
        Node element = null;

        if (!isElement(parentNode)) {
            return null;
        } else {
            NodeList childList = parentNode.getChildNodes();
            for (int nodeIx = 0; nodeIx < childList.getLength(); nodeIx++) {
                Node node = childList.item(nodeIx);
                if (isElement(node)) {
                    return node;
                }
            }
        }

        return null;
    }

    public static boolean isElement(Node node) {
        return node != null
                && (node.getNodeType() == Node.ELEMENT_NODE || node.getNodeType() == Node.DOCUMENT_NODE);
    }
}