Java tutorial
//package com.java2s; //License from project: Open Source License import org.w3c.dom.Document; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { /** Returns the first element with the given name from a document. * * @param doc Document to be searched * @param name The element name to search for * @return Node representing the element */ public static Node getNodeByName(Document doc, String name) { Node retVal = null; NodeList nl = doc.getElementsByTagName(name); if (nl != null && nl.getLength() != 0) retVal = nl.item(0); return retVal; } }