Java tutorial
//package com.java2s; //License from project: Open Source License import java.util.Collection; import java.util.LinkedList; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { public static Collection<Node> search_nodes_by_attribute(Node root, String attr_name, String attr_value) { Collection<Node> result = new LinkedList<Node>(); if (root instanceof Element) { if (((Element) root).hasAttribute(attr_name) && ((Element) root).getAttribute(attr_name).equals(attr_value)) result.add(root); } NodeList list = root.getChildNodes(); for (int i = 0; i < list.getLength(); ++i) { Node child = list.item(i); Collection<Node> ret = search_nodes_by_attribute(child, attr_name, attr_value); result.addAll(ret); } return result; } }