Java XML Element Get getElementsByTagName(Element element, String tagName)

Here you can find the source of getElementsByTagName(Element element, String tagName)

Description

get Elements By Tag Name

License

LGPL

Declaration

public static List<Element> getElementsByTagName(Element element, String tagName) 

Method Source Code

//package com.java2s;
/*/*from w w  w .  j  av  a  2 s  . com*/
 * JFox - The most lightweight Java EE Application Server!
 * more details please visit http://www.huihoo.org/jfox or http://www.jfox.org.cn.
 *
 * JFox is licenced and re-distributable under GNU LGPL.
 */

import java.util.ArrayList;

import java.util.List;

import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Main {
    public static List<Element> getElementsByTagName(Element element, String tagName) {
        ArrayList<Element> children = new ArrayList<Element>();
        if (element != null && tagName != null) {
            NodeList nodes = element.getElementsByTagName(tagName);
            for (int i = 0; i < nodes.getLength(); i++) {
                Node child = nodes.item(i);
                children.add((Element) child);
            }
        }
        return children;
    }
}

Related

  1. getElements(final String elementName, final InputStream is, final boolean onlyValues)
  2. getElementsByName(Element elem, String s)
  3. getElementsByTag(Element element, String tag)
  4. getElementsByTagName(Element aElement, String aTagName)
  5. getElementsByTagName(Element element, String tag)
  6. getElementsByTagName(Element node, String tagName)
  7. getElementsByTagName(Element node, String xmlns, String nodeName)
  8. getElementsByTagNameNS1(Element element, String nsName, String tagName)
  9. getElementsByTagNameNS1(Element element, String nsName, String tagName)