Here you can find the source of findElementWithUniqueAttribute(Element root, String elementName, String attribute, String attributeValue)
public static Element findElementWithUniqueAttribute(Element root, String elementName, String attribute, String attributeValue)
//package com.java2s; /* ***** BEGIN LICENSE BLOCK ***** * Version: GPL 2.0/* www . j a v a 2s . co m*/ * * The contents of this file are subject to the GNU General Public * License Version 2 or later (the "GPL"). * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Initial Developer of the Original Code is * MiniG.org project members * * ***** END LICENSE BLOCK ***** */ import org.w3c.dom.Element; import org.w3c.dom.NodeList; public class Main { public static Element findElementWithUniqueAttribute(Element root, String elementName, String attribute, String attributeValue) { NodeList list = root.getElementsByTagName(elementName); for (int i = 0; i < list.getLength(); i++) { Element tmp = (Element) list.item(i); if (tmp.getAttribute(attribute).equals(attributeValue)) { return tmp; } } return null; } }