Here you can find the source of getElementsByTagName(Element element, String tag)
Parameter | Description |
---|---|
element | the element |
tag | the tag |
public static List<Element> getElementsByTagName(Element element, String tag)
//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; import org.w3c.dom.NodeList; public class Main { /**/* w ww . jav a 2 s. co m*/ * get single element by tag name. * * @param element the element * @param tag the tag * @return the elements by tag name */ public static List<Element> getElementsByTagName(Element element, String tag) { List<Element> elems = new ArrayList<Element>(); NodeList list = element.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { Node node = list.item(i); if (node instanceof Element) { Element e = (Element) node; if (e.getTagName().equals(tag)) { elems.add(e); } } } return elems; } }