Java tutorial
//package com.java2s; import java.util.ArrayList; import java.util.List; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { /** * Get specified child nodes by tag name. * * @param parent * the parent node * @param tagName * the tag name * @param searchDeeper * search deeper? * @return the child node list * @throws Exception * on error */ public static List<Node> getChildNode(Node parent, String tagName, boolean searchDeeper) throws Exception { List<Node> list = new ArrayList<Node>(); if (null != parent) { NodeList childrenList = parent.getChildNodes(); int childrenCnt = childrenList.getLength(); for (int i = 0; i < childrenCnt; i++) { Node child = childrenList.item(i); if (child.getNodeName().equals(tagName)) { list.add(child); } if (searchDeeper) { list.addAll(getChildNode(child, tagName, searchDeeper)); } } } return list; } }