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

import org.w3c.dom.Element;

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

public class Main {
    public static Iterator getElementsByTagNames(Element element, String[] tags) {
        List<Element> children = new ArrayList<Element>();
        if (element != null && tags != null) {
            List tagList = Arrays.asList(tags);
            NodeList nodes = element.getChildNodes();
            for (int i = 0; i < nodes.getLength(); i++) {
                Node child = nodes.item(i);
                if (child.getNodeType() == Node.ELEMENT_NODE && tagList.contains(((Element) child).getTagName())) {
                    children.add((Element) child);
                }
            }
        }
        return children.iterator();
    }
}