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 {
    /**
     * this function will go recursively deep to find the node with the name
     * @param n
     * @param name
     * @return
     */
    public static Node getNodeByName(Node n, String name) {
        NodeList l = n.getChildNodes();
        if (l == null)
            return null;

        for (int i = 0; i < l.getLength(); i++) {
            if (l.item(i).getNodeName().equals(name))
                return l.item(i);
            else {
                Node n2 = getNodeByName(l.item(i), name);
                if (n2 != null) {
                    return n2;
                }
            }
        }
        return null;
    }
}