Java tutorial
//package com.java2s; import java.util.ArrayList; import java.util.List; import org.w3c.dom.Element; import org.w3c.dom.Node; public class Main { public static List<Element> elements(Element root) { List<Element> L = new ArrayList<Element>(); if (root == null) return L; for (Node n1 = root.getFirstChild(); n1 != null; n1 = n1.getNextSibling()) { if (n1.getNodeType() != Node.ELEMENT_NODE) continue; Element e2 = Element.class.cast(n1); L.add(e2); } return L; } public static List<Element> elements(Element root, String tagName) { List<Element> L = new ArrayList<Element>(); if (root == null) return L; for (Node n1 = root.getFirstChild(); n1 != null; n1 = n1.getNextSibling()) { if (n1.getNodeType() != Node.ELEMENT_NODE) continue; Element e2 = Element.class.cast(n1); if (e2.getTagName().equals(tagName)) { L.add(e2); } } return L; } public static List<Element> elements(Element root, String namepaceUri, String localName) { List<Element> L = new ArrayList<Element>(); if (root == null) return L; for (Node n1 = root.getFirstChild(); n1 != null; n1 = n1.getNextSibling()) { if (n1.getNodeType() != Node.ELEMENT_NODE) continue; Element e2 = Element.class.cast(n1); if (namepaceUri.equals(e2.getNamespaceURI()) && e2.getLocalName().equals(localName)) { L.add(e2); } } return L; } }