Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Main {
    /** Returns the first child element with the given name from an element.
     *
     *  @param node The parent element to be searched
     *  @param name The element name to search for
     *  @return Node representing the element
     */
    public static Node getSubnodeByName(Node node, String name) {
        Node retVal = null;
        NodeList nl = node.getChildNodes();
        if (nl != null && nl.getLength() != 0) {
            for (int i = 0; i < nl.getLength(); i++)
                if (nl.item(i).getNodeName().equals(name)) {
                    retVal = nl.item(i);
                    break;
                }
        }
        return retVal;
    }
}