Java tutorial
//package com.java2s; //License from project: Open Source License import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { public static Element findElementNodeByName(Node node, String name) { if (node == null) { return null; } NodeList nodeList = node.getChildNodes(); if (nodeList == null || nodeList.getLength() == 0) { return null; } for (int i = 0; i < nodeList.getLength(); i++) { Node item = nodeList.item(i); if (item != null && (node.getNodeType() == Node.ELEMENT_NODE || node.getNodeType() == Node.DOCUMENT_NODE) && name.equalsIgnoreCase(item.getNodeName())) { return (Element) item; } else { Element element = findElementNodeByName(item, name); if (element != null) { return element; } } } return null; } }