Java tutorial
//package com.java2s; import org.w3c.dom.*; import java.util.ArrayList; import java.util.List; public class Main { public static List<Node> getGrandSonElementsByTagName(Element ele, String parentName, String eleName) { NodeList nl = ele.getElementsByTagName(parentName); if (null == nl) { return null; } Node item = nl.item(0); if (null == item) { return null; } NodeList subNodeList = item.getChildNodes(); List<Node> childEles = new ArrayList<Node>(); Node node = null; for (int i = 0; i < subNodeList.getLength(); i++) { node = subNodeList.item(i); if (node != null) { if (node instanceof Element && eleName.equals(node.getNodeName()) || eleName.equals(node.getLocalName())) { childEles.add(node); } } } return childEles; } }