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;

public class Main {
    /**
     * Returns a list of elements having a given tag
     */
    public static List<Element> getElements(Element element, String tagName) {
        Node node = element.getFirstChild();
        List<Element> elements = new ArrayList<Element>();

        while (node != null) {
            if (node.getNodeType() == Node.ELEMENT_NODE && node.getNodeName().compareTo(tagName) == 0)
                elements.add((Element) node);

            node = node.getNextSibling();
        }

        return elements;
    }
}