Java tutorial
//package com.java2s; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { /** * Get a node from a list with a specific attribute value. * * @param nodeList the list of nodes * @param name the name of the attribute to check against * @param value the value to match * @return the node with matching attribute value */ public static Node getNodeWithGivenValue(final NodeList nodeList, final String name, final String value) { Node node = null; for (int i = 0; i < nodeList.getLength(); i++) { final NamedNodeMap map = nodeList.item(i).getAttributes(); if (map != null) { for (int j = 0; j < map.getLength(); j++) { if ((name.equals(map.item(j).getNodeName())) && (value.equals(map.item(j).getTextContent()))) { node = nodeList.item(i); } } } } return node; } }