Java tutorial
//package com.java2s; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { public static Node getElementByTagName(Document document, String tagname) { NodeList nodeList = document.getElementsByTagName(tagname); if (nodeList != null && nodeList.getLength() > 0) { return nodeList.item(0); } else { return null; } } public static Node getElementByTagName(Element element, String tagname) { NodeList nodeList = element.getElementsByTagName(tagname); if (nodeList != null && nodeList.getLength() > 0) { return nodeList.item(0); } else { return null; } } }