Here you can find the source of getElementsByTagName(Element node, String tagName)
Parameter | Description |
---|---|
node | The parent node element. |
tagName | The child element's tagName. |
public static ArrayList<Element> getElementsByTagName(Element node, String tagName)
//package com.java2s; /***************************************************************************** * Web3d Consortium Copyright (c) 2007 - 2008 * Java Source * * This source is licensed under the GNU LGPL v2.1 * Please read http://www.gnu.org/copyleft/lgpl.html for more information * * This software comes with the standard NO WARRANTY disclaimer for any * purpose. Use it at your own risk. If there's a problem you get to fix it. * *****************************************************************************/ import java.util.ArrayList; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { /**/*from ww w . j av a2 s. c om*/ * Search the children of the argument node for named elements. * * @param node The parent node element. * @param tagName The child element's tagName. * @return The list of elements. */ public static ArrayList<Element> getElementsByTagName(Element node, String tagName) { ArrayList<Element> list = new ArrayList<Element>(); NodeList nl = node.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node n = nl.item(i); if (n.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) n; if (e.getTagName().equals(tagName)) { list.add(e); } } } return (list); } }