Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

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

public class Main {
    /**
     * get single element by tag name
     * @param element
     * @param tag
     * @return
     */
    public static Element getElementByTagName(Element element, String tag) {
        NodeList list = element.getChildNodes();
        for (int i = 0; i < list.getLength(); i++) {
            Node node = list.item(i);
            if (node instanceof Element && ((Element) node).getTagName().equals(tag)) {
                return (Element) node;
            }
        }
        return null;
    }
}