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.NodeList;

public class Main {
    /**
     * Returns a list with the elements included in the childrens of element
     * that have name = tag.
     * @param element Element
     * @param tag name of the Element.
     * @return List with the indicated elements.
     */
    public static List<Element> childsTags(Element element, String tag) {
        NodeList nl = element.getChildNodes();

        ArrayList<Element> ret = new ArrayList<Element>();

        if (nl != null) {
            int length = nl.getLength();

            for (int i = 0; i < length; i++) {
                if (tag.equals((nl.item(i)).getNodeName())) {
                    ret.add((Element) nl.item(i));
                }
            }
        }
        return ret;
    }
}