Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

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

public class Main {
    /**
     * Returns the child of the given node which has the specified name
     * If no such node exists, returns null
     */
    public static Node findChild(Node parent, String name) {
        // Iterate through the collection of children
        NodeList nodes = parent.getChildNodes();
        for (int a = 0; a != nodes.getLength(); ++a) {
            Node node = nodes.item(a);
            if (node.getNodeName().equals(name)) {
                // This is the one
                return node;
            }
        }

        // No such node
        return null;
    }
}