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 {
    /**
     * Gets first child element with specified name.
     *
     * @param parentNode parent node.
     * @param childName  child name.
     * @return first childr element with specified name.
     */
    public static Element getChildElement(final Node parentNode, final String childName) {
        //        parentNode.normalize();
        final NodeList nodeList = parentNode.getChildNodes();
        for (int i = 0; i < nodeList.getLength(); i++) {
            final Node node = nodeList.item(i);
            if (node.getNodeType() == Node.ELEMENT_NODE && node.getNodeName().equals(childName))
                return (Element) node;
        }
        return null;
    }
}