Java tutorial
//package com.java2s; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { public static String getSubTagAttribute(Element root, String tagName, String subTagName, String attribute) { String returnString = ""; NodeList list = root.getElementsByTagName(tagName); for (int loop = 0; loop < list.getLength(); loop++) { Node node = list.item(loop); if (node != null) { NodeList children = node.getChildNodes(); for (int innerLoop = 0; innerLoop < children.getLength(); innerLoop++) { Node child = children.item(innerLoop); if ((child != null) && (child.getNodeName() != null) && child.getNodeName().equals(subTagName)) { if (child instanceof Element) { return ((Element) child).getAttribute(attribute); } } } // end inner loop } } return returnString; } }