Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.ArrayList;

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

public class Main {
    /**
     * get all child elements matching the given tag 
     * 
     * @param tag
     * @param searchIn
     * @return
     */
    public static ArrayList<Element> getChildElementsByTag(String tag, Element searchIn) {
        ArrayList<Element> toReturn = new ArrayList<Element>();
        NodeList list = searchIn.getChildNodes();

        for (int i = 0; i < list.getLength(); i++) {
            Node n = list.item(i);
            if (n instanceof Element && ((Element) n).getTagName().equals(tag)) {
                toReturn.add((Element) n);
            }

        }
        return toReturn;
    }
}