Here you can find the source of getElementByAttributeValue(Node start, String tagName, String attrName, String attrValue)
public static Element getElementByAttributeValue(Node start, String tagName, String attrName, String attrValue)
//package com.java2s; /*/*from w w w . j a va2 s . co m*/ * Copyright (c) 2012. betterFORM Project - http://www.betterform.de * Licensed under the terms of BSD License */ import org.w3c.dom.*; public class Main { /** * equivalent to the XPath expression './/tagName[@attrName='attrValue']' */ public static Element getElementByAttributeValue(Node start, String tagName, String attrName, String attrValue) { NodeList nl = ((Element) start).getElementsByTagName(tagName); int l = nl.getLength(); if (l == 0) { return null; } Element e = null; String compareValue = null; for (int i = 0; i < l; i++) { e = (Element) nl.item(i); if (e.getNodeType() == Node.ELEMENT_NODE) { compareValue = e.getAttribute(attrName); if (compareValue.equals(attrValue)) { return e; } } } return null; } }