Here you can find the source of getNodeAttributeDeep(NodeList nodelList, String nodeName, String nodeAttr)
public static String getNodeAttributeDeep(NodeList nodelList, String nodeName, String nodeAttr)
//package com.java2s; //License from project: Open Source License import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { public static String getNodeAttributeDeep(NodeList nodelList, String nodeName, String nodeAttr) { for (int i = 0; i < nodelList.getLength(); i++) { Node node = nodelList.item(i); if (node.getNodeName().equals(nodeName)) { return getNodeAttribute(node, nodeAttr); }/*w w w . j ava 2s.co m*/ if (node.getChildNodes().getLength() > 0) { String result = getNodeAttributeDeep(node.getChildNodes(), nodeName, nodeAttr); if (result != null) return result; } } return null; } public static String getNodeAttribute(Node node, String s) { NamedNodeMap attributes = node.getAttributes(); for (int k = 0; k < attributes.getLength(); k++) { Node nodeAttr = attributes.item(k); if (nodeAttr.getNodeName().equals(s)) { return nodeAttr.getNodeValue(); } } return null; } }