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 java.util.List;

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

public class Main {
    public static List<Element> getChildElementsByTagName(Element element, String name) {
        List<Element> result = new ArrayList<Element>();

        NodeList childNodes = element.getChildNodes();
        for (int i = 0; i < childNodes.getLength(); i++) {
            Node node = childNodes.item(i);
            if (node instanceof Element) {
                String nodeName = node.getNodeName();
                if (nodeName != null) {
                    if (nodeName.equals(name)) {
                        result.add((Element) childNodes.item(i));
                    }
                }

            }
        }

        if (result.size() == 0) {
            result = null;
        }
        return result;
    }
}