Here you can find the source of getElementList(Element dataRoot, String name)
Parameter | Description |
---|---|
rootElement | the starting node |
subElementName | the name of the subelement to find |
public static List<Element> getElementList(Element dataRoot, String name)
//package com.java2s; /**/*from w ww . j a va 2 s. co m*/ * 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 rootElement * the starting node * @param subElementName * 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; } }