Here you can find the source of getElementByTagName(Element parent, String elementName)
Parameter | Description |
---|---|
parent | Parent Element |
elementName | Tag name of the child element to be returned. |
public static final Element getElementByTagName(Element parent, String elementName)
//package com.java2s; import org.w3c.dom.Element; import org.w3c.dom.NodeList; public class Main { /**//from w ww.ja v a 2 s . c om * Get a child element with a given tag name. If multiple child elements exist with the same tag name, the first * child element is returned. * * @param parent * Parent Element * @param elementName * Tag name of the child element to be returned. * * @return First child element which has the given tag name. */ public static final Element getElementByTagName(Element parent, String elementName) { NodeList nodeList = parent.getElementsByTagName(elementName); if (nodeList.getLength() > 0) { return (Element) nodeList.item(0); } return null; } }