Java tutorial
//package com.java2s; import java.util.*; import org.w3c.dom.*; public class Main { public static List<Node> getChildrenByTagName(Node node, String element) { List<Node> result = new ArrayList<Node>(); NodeList childNodes = node.getChildNodes(); for (int j = 0; j < childNodes.getLength(); j++) { Node childNode = childNodes.item(j); if ("*".equals(element) || element == null || childNode.getNodeName().equals(element)) { result.add(childNode); } } return result; } public static List<Node> getChildNodes(Node node, String... elements) { List<Node> result = new ArrayList<Node>(); NodeList childNodes = node.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node childNode = childNodes.item(i); for (String element : elements) { if (element.equals(childNode.getNodeName())) { result.add(childNode); } } } return result; } }