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.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Main {
    public static Node search_node_by_attribute(Node root, String attr_name, String attr_value) {
        if (root instanceof Element) {
            if (((Element) root).hasAttribute(attr_name)
                    && ((Element) root).getAttribute(attr_name).equals(attr_value))
                return root;
        }
        NodeList list = root.getChildNodes();
        for (int i = 0; i < list.getLength(); ++i) {
            Node child = list.item(i);
            Node ret = search_node_by_attribute(child, attr_name, attr_value);
            if (ret != null)
                return ret;
        }
        return null;
    }
}