Here you can find the source of getElementWithAttribute(String tagName, String attribute, String attributeValue, Element searchIn)
public static Element getElementWithAttribute(String tagName, String attribute, String attributeValue, Element searchIn)
//package com.java2s; import java.util.ArrayList; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { /**/*from w w w . java 2 s.c o m*/ */ public static Element getElementWithAttribute(String tagName, String attribute, String attributeValue, Element searchIn) { ArrayList<Element> list = getElementsByTag(tagName, searchIn); for (Element e : list) { if (attributeValue.equals(e.getAttribute(attribute))) { return e; } } return null; } /** */ public static ArrayList<Element> getElementsByTag(String tag, Element searchIn) { NodeList list = searchIn.getElementsByTagName(tag); ArrayList<Element> toReturn = new ArrayList<Element>(); for (int i = 0; i < list.getLength(); i++) { Node n = list.item(i); if (!(n instanceof Element)) { continue; } toReturn.add((Element) n); } return toReturn; } }