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