Java tutorial
//package com.java2s; //License from project: Open Source License import org.w3c.dom.Element; import org.w3c.dom.Node; public class Main { public static Element getNode(Element e, String name) { Node n = e.getElementsByTagName(name).item(0); if (n == null) return e; else if (n.getNodeType() == Node.ELEMENT_NODE) { return (Element) n; } else return e; } }