Here you can find the source of getChildElements(Element element, String childrenName)
Parameter | Description |
---|---|
element | a parameter |
childrenName | a parameter |
public static List<Element> getChildElements(Element element, String childrenName)
//package com.java2s; //License from project: Open Source License import java.util.LinkedList; import java.util.List; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { /**/*from www . j av a2s.c om*/ * Given an XML element, this method returns nested elements which are direct * children of the given element - but only those that have the element-name "childrenName" (the second parameter). * @param element * @param childrenName * @return */ public static List<Element> getChildElements(Element element, String childrenName) { List<Element> ret = new LinkedList<Element>(); NodeList nodeList = element.getChildNodes(); for (int index = 0; index < nodeList.getLength(); ++index) { Node node = nodeList.item(index); if (node instanceof Element) { Element elementOfNode = (Element) node; if (elementOfNode.getTagName().equals(childrenName)) { ret.add(elementOfNode); } } } return ret; } }