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 Element get_child_with_attr(Node parent, String child_name, String attr_name, String attr_value) {
        NodeList children = parent.getChildNodes();
        for (int i = 0; i < children.getLength(); ++i) {
            Node child = children.item(i);
            if (child.getNodeName().equals(child_name)) {
                if (child instanceof Element) {
                    Element e = (Element) child;
                    if (e.getAttribute(attr_name).equals(attr_value))
                        return e;
                }
            }
        }
        return null;
    }
}