Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

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> getElements(final Element element, final String tagName) {
        final ArrayList<Element> elements = new ArrayList<>();
        final NodeList children = element.getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            final Node node = children.item(i);
            if (node.getNodeType() == Node.ELEMENT_NODE) {
                final String nodeName = node.getNodeName();
                if ((nodeName != null) && nodeName.equals(tagName)) {
                    elements.add((Element) node);
                }
            }
        }
        return elements;
    }
}