Here you can find the source of getElementsByTagName(Node node, String tagname)
static public List<Element> getElementsByTagName(Node node, String tagname)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.List; import org.w3c.dom.Document; import org.w3c.dom.NodeList; import org.w3c.dom.Node; import org.w3c.dom.Element; public class Main { static public List<Element> getElementsByTagName(Node node, String tagname) { ArrayList<Element> list = new ArrayList<Element>(); NodeList nl;/*w w w. j av a2s . c o m*/ if (node.getNodeType() == Node.DOCUMENT_NODE) { nl = ((Document) node).getElementsByTagName(tagname); } else if (node.getNodeType() == Node.ELEMENT_NODE) { nl = ((Element) node).getElementsByTagName(tagname); } else { return null; } for (int i = 0; i < nl.getLength(); i++) { list.add((Element) nl.item(i)); } return list; } }