Java tutorial
//package com.java2s; import java.util.ArrayList; import java.util.List; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { /** * Returns a List of all descendant Element nodes having the specified * [namespace name] property. The elements are listed in document order. * * @param node The node to search from. * @param namespaceURI An absolute URI denoting a namespace name. * @return A List containing elements in the specified namespace; the list * is empty if there are no elements in the namespace. */ public static List<Element> getElementsByNamespaceURI(Node node, String namespaceURI) { List<Element> list = new ArrayList<Element>(); NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (child.getNodeType() != Node.ELEMENT_NODE) { continue; } if (child.getNamespaceURI().equals(namespaceURI)) { list.add((Element) child); } } return list; } }