Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
// License as published by the Free Software Foundation; either

import org.w3c.dom.Element;

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

public class Main {
    public static Element getChildWithAttribute(Element element, String attributeName) {

        if (element == null) {
            return null;
        }

        NodeList children = element.getChildNodes();

        for (int loop = 0, length = children.getLength(); loop < length; loop++) {
            Node node = children.item(loop);

            if (!(node instanceof Element)) {
                continue;
            }

            Element child = (Element) node;

            if (child.hasAttribute(attributeName)) {
                return child;
            }
        }

        return null;
    }
}