Here you can find the source of getFirstChildElementByTagName(Node element, String tagName)
Parameter | Description |
---|---|
element | a parameter |
tagName | a parameter |
public static Element getFirstChildElementByTagName(Node element, String tagName)
//package com.java2s; // are made available under the terms of the Eclipse Public License v1.0 import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { /**// w w w. ja va2s . c om * Gets the first element with the given tag name in the immediate child elements. * * @param element * @param tagName * @return */ public static Element getFirstChildElementByTagName(Node element, String tagName) { NodeList list = element.getChildNodes(); int size = list.getLength(); if (size > 0) { for (int i = 0; i < size; i++) { Node node = list.item(i); if (node instanceof Element) { Element e = (Element) node; if (e.getTagName().equals(tagName)) { return e; } } } } return null; } }