Here you can find the source of getChildElementsByTagName(Element element, String tagName)
Parameter | Description |
---|---|
element | a parameter |
tagName | a parameter |
public static List<Element> getChildElementsByTagName(Element element, String tagName)
//package com.java2s; // are made available under the terms of the Eclipse Public License v1.0 import java.util.ArrayList; 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. j a v a 2 s .c o m*/ * Gets the list of immediate child elements with the given tag name. * * @param element * @param tagName * @return list of {@link Element} objects */ public static List<Element> getChildElementsByTagName(Element element, String tagName) { List<Element> elements = new ArrayList<Element>(); NodeList list = element.getChildNodes(); int size = list.getLength(); if (size > 0) { for (int i = 0; i < size; i++) { Node node = list.item(i); if (node instanceof Element) { Element e = (Element) node; if (e.getTagName().equals(tagName)) { elements.add(e); } } } } return elements; } }