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 {
    /**
     * Extracts the {@link Element} for the given name from the parent.
     * 
     * @param parent
     * @param name
     * @return
     */
    public static <T extends Node> T findNode(Node parent, Class<T> type, String name) {
        final NodeList childNodes = parent.getChildNodes();

        for (int i = 0; i < childNodes.getLength(); i++) {
            final Node child = childNodes.item(i);
            if (type.isAssignableFrom(child.getClass()) && name.equals(child.getNodeName())) {
                return type.cast(child);
            }
        }
        return null;
    }
}