Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import java.util.ArrayList;

import org.w3c.dom.Element;
import org.w3c.dom.Node;

public class Main {
    public static Element getElementByTagName(Element n, String elementName) {
        int sz = n.getChildNodes().getLength();
        ArrayList<Element> elements = new ArrayList<Element>(sz);
        for (int idx = 0; idx < sz; idx++) {
            Node node = n.getChildNodes().item(idx);
            if (node instanceof Element && node.getLocalName().equals(elementName))
                elements.add((Element) node);
        }
        if (elements.size() > 0)
            return elements.get(0);
        return null;
    }
}