Here you can find the source of getChildElements(Element parent, String name)
Parameter | Description |
---|---|
parent | The parent. |
name | Only elements with this name will be included, or if "*", includes all child elements. |
public static List<Element> getChildElements(Element parent, String name)
//package com.java2s; import org.w3c.dom.Element; import org.w3c.dom.Node; import java.util.ArrayList; import java.util.List; public class Main { /**//from www . j a v a 2 s. c o m * Returns all the direct children of the parent that are {@link Element} * nodes. * * @param parent The parent. * @param name Only elements with this name will be included, or if "*", * includes all child elements. */ public static List<Element> getChildElements(Element parent, String name) { List<Element> kids = new ArrayList<Element>(); for (Node n = parent.getFirstChild(); n != null; n = n.getNextSibling()) { if ((name.equals("*") || n.getNodeName().equals(name)) && n instanceof Element) { kids.add((Element) n); } } return kids; } }