Here you can find the source of getChildElementsByName(final Element parent, final String name)
Parameter | Description |
---|---|
parent | the parent element |
name | the expected name of the childs |
public static List<Element> getChildElementsByName(final Element parent, final String name)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.List; import org.w3c.dom.Element; import org.w3c.dom.Node; public class Main { /**// ww w . j a v a 2 s. co m * Returns all elements in the parent that match the specified name. * * @param parent * the parent element * @param name * the expected name of the childs * * @return the elements, the list might be empty if there is no match */ public static List<Element> getChildElementsByName(final Element parent, final String name) { List<Element> elements = new ArrayList<Element>(); if (parent != null) { Node child = parent.getFirstChild(); while (child != null) { if (child.getNodeType() == Node.ELEMENT_NODE && child.getNodeName().equals(name)) { elements.add((Element) child); } child = child.getNextSibling(); } } return elements; } }