Here you can find the source of getElementByAttribute(String attr, String value, Element root)
public final static Element getElementByAttribute(String attr, String value, Element root)
//package com.java2s; //License from project: Apache License import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { public final static Element getElementByAttribute(String attr, String value, Element root) { Element found = null;//w ww .ja va 2 s. co m if (root.hasAttribute(attr) && root.getAttribute(attr).equals(value)) { return root; } NodeList nl = root.getChildNodes(); for (int i = nl.getLength() - 1; i >= 0; i--) { if (nl.item(i).getNodeType() == Node.ELEMENT_NODE) { found = getElementByAttribute(attr, value, (Element) nl.item(i)); if (found != null) { return found; } } } return null; } }