Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/**
 * The contents of this file are subject to the license and copyright
 * detailed in the LICENSE and NOTICE files at the root of the source
 * tree and available online at
 *
 * http://www.dspace.org/license/
 */

import java.util.ArrayList;

import java.util.List;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

public class Main {
    /**
     * 
     * @param dataRoot
     *            the starting node
     * @param name
     *            the name of the subelement to find
     * @return the list of all DOM Element with the provided name direct child
     *         of the starting node
     */
    public static List<Element> getElementList(Element dataRoot, String name) {
        NodeList list = dataRoot.getElementsByTagName(name);
        List<Element> listElements = new ArrayList<Element>();
        for (int i = 0; i < list.getLength(); i++) {
            Element item = (Element) list.item(i);
            if (item.getParentNode().equals(dataRoot)) {
                listElements.add(item);
            }
        }
        return listElements;
    }
}