Here you can find the source of findElement(Document doc, String elementNS, String elementName, String attrName, String attrValue)
public static Element findElement(Document doc, String elementNS, String elementName, String attrName, String attrValue)
//package com.java2s; //License from project: Apache License import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; public class Main { public static Element findElement(Document doc, String elementNS, String elementName, String attrName, String attrValue) {//w w w . j a va 2 s .co m return findElement(doc.getDocumentElement(), elementNS, elementName, attrName, attrValue); } public static Element findElement(Element parent, String elementNS, String elementName, String attrName, String attrValue) { NodeList l = parent.getElementsByTagNameNS(elementNS, elementName); for (int i = 0; i < l.getLength(); i++) { Element e = (Element) l.item(i); String val = e.getAttribute(attrName); if (val != null && val.equals(attrValue)) { return e; } } return null; } }