Here you can find the source of getElementByTagName(Element element, String tag)
Parameter | Description |
---|---|
element | a parameter |
tag | a parameter |
public static Element getElementByTagName(Element element, String tag)
//package com.java2s; //License from project: Apache License import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { /**/* w w w. ja v a 2s .c om*/ * get single element by tag name * @param element * @param tag * @return */ public static Element getElementByTagName(Element element, String tag) { NodeList list = element.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { Node node = list.item(i); if (node instanceof Element && ((Element) node).getTagName().equals(tag)) { return (Element) node; } } return null; } }