Here you can find the source of findNodeByAttribute(Document document, String tagName, String attributeName, String attributeValue)
public static Node findNodeByAttribute(Document document, String tagName, String attributeName, String attributeValue)
//package com.java2s; //License from project: Apache License import org.w3c.dom.Document; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { public static Node findNodeByAttribute(Document document, String tagName, String attributeName, String attributeValue) { Node foundNode = null;//from ww w .java2s . co m NodeList nodes = document.getElementsByTagName(tagName); for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); for (int j = 0; j < node.getAttributes().getLength(); j++) { Node attribute = node.getAttributes().item(j); if (attribute.getNodeName().equals(attributeName) && attribute.getNodeValue().equals(attributeValue)) { foundNode = node; break; } } if (foundNode != null) break; } return foundNode; } }