Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import org.w3c.dom.*;

public class Main {
    /**
     * Returns the first node that is a direct child of root with the coresponding
     * name.  Does not search children of children.
     */
    public static Element getFirstChild(Element root, String name) {
        NodeList nl = root.getChildNodes();
        int size = nl.getLength();
        for (int i = 0; i < size; i++) {
            Node node = nl.item(i);
            if (!(node instanceof Element))
                continue;
            Element ele = (Element) node;
            if (ele.getTagName().equals(name))
                return ele;
        }

        return null;
    }
}