Here you can find the source of getElementByTagAndName(Document document, String tagName, String elementName)
public static Element getElementByTagAndName(Document document, String tagName, String elementName)
//package com.java2s; /*L//from w ww. j av a 2s. c om * Copyright Georgetown University, Washington University. * * Distributed under the OSI-approved BSD 3-Clause License. * See http://ncip.github.com/cab2b/LICENSE.txt for details. */ import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; public class Main { public static Element getElementByTagAndName(Document document, String tagName, String elementName) { NodeList nodeList = document.getElementsByTagName(tagName); Element element = null; if (elementName != null) { Element _element = null; for (int nodeIndex = 0; nodeIndex < nodeList.getLength(); nodeIndex++) { _element = (Element) nodeList.item(nodeIndex); String name = _element.getAttribute("name"); if (name != null && name.equals(elementName)) { element = _element; break; } } } else { element = (Element) document.getElementsByTagName(tagName) .item(0); } return element; } }