Java tutorial
//package com.java2s; //License from project: Open Source License import java.util.Collection; import java.util.LinkedList; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { public static Collection<Node> search_nodes_by_name(Node root, String name) { Collection<Node> result = new LinkedList<Node>(); if (root.getNodeName().equals(name)) 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_name(child, name); result.addAll(ret); } return result; } }