Java tutorial
//package com.java2s; //License from project: Open Source License import java.util.*; import org.w3c.dom.*; public class Main { private static final String DOM_WILDCARD = "*"; /** * This method returns a list of the direct element node children of this element node with the specified tag. * @param node - parent node * @param tag - tag of direct children to be returned * @return a list containing the direct element children with the given tag * @author Tristan Bepler */ public static List<Element> getDirectChildElementsByTag(Element node, String tag) { List<Element> children = new ArrayList<Element>(); Node child = node.getFirstChild(); while (child != null) { if (child.getNodeType() == Node.ELEMENT_NODE && (child.getNodeName().equals(tag) || tag.equals(DOM_WILDCARD))) { children.add((Element) child); } child = child.getNextSibling(); } return children; } }