Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

public class Main {
    /**
     * Returns the first Element node in a NodeList
     * @param list the list to search
     * @return the element or null if none is found
     */
    public static Element getFirstElement(NodeList list) {
        if (list.getLength() == 0) {
            return null;
        }

        Node node = list.item(0);
        while (node.getNodeType() != Node.ELEMENT_NODE) {
            if (node.getNextSibling() == null) {
                return null;
            }
            node = node.getNextSibling();
        }
        return (Element) node;
    }
}