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 {
    /**
     * @param elem
     * @param childTag
     * @return
     */
    public static Element getFirstChild(Element elem, String childTag) {
        if (elem.hasChildNodes()) {
            NodeList list = elem.getElementsByTagName(childTag);
            int count = list.getLength();

            for (int i = 0; i < count; i++) {
                Node node = list.item(i);
                if (node.getParentNode() != elem)
                    continue;

                if (node.getNodeType() == Node.ELEMENT_NODE) {
                    return (Element) node;
                }
            }
        }

        return null;
    }
}