Here you can find the source of getGrandSonElementByTagName(Element element, String parentName, String eleName)
public static Element getGrandSonElementByTagName(Element element, String parentName, String eleName)
//package com.java2s; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { public static Element getGrandSonElementByTagName(Element element, String parentName, String eleName) { NodeList nl = element.getElementsByTagName(parentName); if (null == nl) { return null; }/* w w w. j a va 2 s . co m*/ Node item = nl.item(0); return getChildElementByTagName((Element) item, eleName); } public static Element getChildElementByTagName(Element ele, String childEleName) { NodeList nl = ele.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node node = nl.item(i); if (node instanceof Element && childEleName.equals(node.getNodeName()) || childEleName.equals(node.getLocalName())) { return (Element) node; } } return null; } }