Here you can find the source of getElementsByTagAndAttr(Element parent, String elemName, String attrName, String attrVal)
public static List<Element> getElementsByTagAndAttr(Element parent, String elemName, String attrName, String attrVal)
//package com.java2s; //License from project: LGPL 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 { public static List<Element> getElementsByTagAndAttr(Element parent, String elemName, String attrName, String attrVal) {// ww w .j a v a2 s .c o m List<Element> result = new ArrayList<Element>(); NodeList nl = parent.getElementsByTagName(elemName); for (int i = 0; i < nl.getLength(); i++) { if (nl.item(i).getNodeType() == Node.ELEMENT_NODE) { Element elem = (Element) nl.item(i); String val = elem.getAttribute(attrName); if (val != null && val.equals(attrVal)) result.add(elem); } } return result; } }