Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source 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> getChildrenWithTag(Element parent, String tag) {
        List<Element> list = getElementChildren(parent);
        for (Element e : list.toArray(new Element[0])) {
            if (!e.getTagName().equals(tag))
                list.remove(e);
        }
        return list;
    }

    public static List<Element> getElementChildren(Element root) {
        NodeList list = root.getChildNodes();
        List<Element> children = new ArrayList<Element>();
        for (int i = 0; i < list.getLength(); i++) {
            Node child = list.item(i);
            if (child instanceof Element)
                children.add((Element) child);
        }
        return children;
    }
}