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 {

    public static Element getChildByName(Element parent, String nodeName) {
        NodeList nodes = parent.getChildNodes();
        int len = nodes.getLength();
        if (nodes != null && len > 0) {
            for (int i = 0; i < len; i++) {
                if (nodes.item(i).getNodeType() == Node.ELEMENT_NODE
                        && nodes.item(i).getNodeName().equals(nodeName)) {
                    return (Element) nodes.item(i);
                }
            }
        }
        return null;
    }
}