Java XML Child Get by Name getChildElementsByTagName(Element parentElement, String childTag)

Here you can find the source of getChildElementsByTagName(Element parentElement, String childTag)

Description

get Child Elements By Tag Name

License

LGPL

Declaration

public static List<Element> getChildElementsByTagName(Element parentElement, String childTag) 

Method Source Code

//package com.java2s;
/*/* w  w  w. ja  v a  2  s.c  o m*/
 * 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> getChildElementsByTagName(Element parentElement, String childTag) {
        NodeList nodelist = parentElement.getChildNodes();
        List<Element> nodes = new ArrayList<Element>();
        for (int i = 0; i < nodelist.getLength(); i++) {
            Node temp = nodelist.item(i);
            if (temp.getNodeType() == Node.ELEMENT_NODE && temp.getNodeName().equals(childTag)) {
                nodes.add((Element) temp);
            }
        }
        return nodes;
    }
}

Related

  1. getChildElementsByTagName(Element ele, String childEleName)
  2. getChildElementsByTagName(Element ele, String childEleName, boolean localName)
  3. getChildElementsByTagName(Element elem, String name)
  4. getChildElementsByTagName(Element element, String name)
  5. getChildElementsByTagName(Element element, String tagName)
  6. getChildElementsByTagName(Element parentElement, String name)
  7. getChildElementsByTagName(Element parentNode, String tagName)
  8. getChildElementsByTagName(final Element element, final String tagName)
  9. getChildElementsByTagName(final Element parentElem, final String childName)