Here you can find the source of getElementsByName(Element elem, String s)
Parameter | Description |
---|---|
element | the element to search in |
s | type/tag of children |
public static List<Element> getElementsByName(Element elem, String s)
//package com.java2s; //License from project: Creative Commons License import java.util.ArrayList; import java.util.List; import org.w3c.dom.Element; import org.w3c.dom.Node; public class Main { /**/* w w w .ja v a 2 s .c o m*/ * get all children of given type or empty list * * @param element * the element to search in * @param s * type/tag of children * @return list of children of given type or empty, never null */ public static List<Element> getElementsByName(Element elem, String s) { List<Element> ret = new ArrayList<Element>(); for (Node child = elem.getFirstChild(); child != null; child = child .getNextSibling()) { if (child instanceof Element) { if (child.getNodeName().equals(s)) { ret.add((Element) child); } } } return ret; } }