Here you can find the source of getElementsWithAttribute(Element element, String namespaceURI, String localName, String value, Collection elements)
private static void getElementsWithAttribute(Element element, String namespaceURI, String localName, String value, Collection elements)
//package com.java2s; //License from project: Apache License import org.w3c.dom.NodeList; import org.w3c.dom.Element; import org.w3c.dom.Node; import java.util.ArrayList; import java.util.Collection; public class Main { /** Get the elements descendant having the specified attribute name and value./* w w w . j a v a 2 s . c om*/ @param element Element whose children we want to search @param namespaceURI Attribute's namespace @param localName Attribute name @param value Attribute value @return list of the elements having this attribute value */ public static Collection getElementsWithAttribute(Element element, String namespaceURI, String localName, String value) { Collection elements = new ArrayList(); getElementsWithAttribute(element, namespaceURI, localName, value, elements); return elements; } private static void getElementsWithAttribute(Element element, String namespaceURI, String localName, String value, Collection elements) { if (element.hasAttributeNS(namespaceURI, localName)) { String attr = element.getAttributeNS(namespaceURI, localName); if (attr.equals(value)) elements.add(element); } NodeList childs = element.getChildNodes(); for (int i = 0; i < childs.getLength(); i++) { Node node = childs.item(i); if (Node.ELEMENT_NODE == node.getNodeType()) getElementsWithAttribute((Element) node, namespaceURI, localName, value, elements); } } }