Java tutorial
//package com.java2s; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; public class Main { public static List<Element> getChildElementsByTagName(Element ele, String childEleName) { return getChildElementsByTagName(ele, new String[] { childEleName }); } public static List<Element> getChildElementsByTagName(Element ele, String... childEleNames) { List<String> childEleNameList = Arrays.asList(childEleNames); NodeList nl = ele.getChildNodes(); List<Element> childEles = new ArrayList<Element>(); for (int i = 0; i < nl.getLength(); i++) { Node node = nl.item(i); if (node instanceof Element && nodeNameMatch(node, childEleNameList)) { childEles.add((Element) node); } } return childEles; } private static boolean nodeNameMatch(Node node, Collection<?> desiredNames) { return (desiredNames.contains(node.getNodeName()) || desiredNames.contains(node.getLocalName())); } private static boolean nodeNameMatch(Node node, String desiredName) { return (desiredName.equals(node.getNodeName()) || desiredName.equals(node.getLocalName())); } }