Here you can find the source of getChildElementsByName(Element parent, String tagName)
Parameter | Description |
---|---|
parent | The element from which the children elements must be retrieved. |
tagName | The tag name of the children elements that must be retrieved |
public static List<Element> getChildElementsByName(Element parent, String tagName)
//package com.java2s; //License from project: Apache 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 w w w . jav a 2 s . c om*/ * Get all child elements of a certain tag name. * * @param parent * The element from which the children elements must be * retrieved. * @param tagName * The tag name of the children elements that must be retrieved * @return A list of children elements. If no elements of the specified tag * name are found, an empty list is returned. */ public static List<Element> getChildElementsByName(Element parent, String tagName) { List<Element> elementList = new LinkedList<Element>(); NodeList children = parent.getChildNodes(); for (int c = 0; c < children.getLength(); c++) { if (children.item(c).getNodeType() == Node.ELEMENT_NODE && children.item(c).getNodeName().equals(tagName)) { elementList.add((Element) children.item(c)); } } return elementList; } }