Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import java.util.LinkedList;
import java.util.List;

public class Main {

    public static List<Element> getElementCollectionFromDocument(Document document, String tagName) {
        List<Element> res = new LinkedList<Element>();
        NodeList entries = document.getElementsByTagName(tagName);
        for (int i = 0; i < entries.getLength(); i++) {
            Node entry = entries.item(i);
            if (entry.getNodeType() == Node.ELEMENT_NODE) {
                res.add((Element) entry);
            }
        }
        return res;
    }
}