Here you can find the source of getElement(Element root, String tagName, String attrName, String attrValue)
public static Element getElement(Element root, String tagName, String attrName, String attrValue)
//package com.java2s; import org.w3c.dom.Element; import org.w3c.dom.NodeList; public class Main { public static Element getElement(Element root, String tagName, String attrName, String attrValue) { if (root.getTagName().equals(tagName)) { if (attrName == null) { return (root); }/* www . j a v a 2s.c om*/ if (root.getAttribute(attrName).equals(attrValue)) { return (root); } } NodeList list = root.getElementsByTagName(tagName); for (int i = 0; i < list.getLength(); i++) { Element el = (Element) list.item(i); if (attrName == null) { return (el); } if (el.getAttribute(attrName).equals(attrValue)) { return (el); } } return (null); } }