Java XML Child Get by Name getChildElementsByTagName(Element elem, String name)

Here you can find the source of getChildElementsByTagName(Element elem, String name)

Description

get Child Elements By Tag Name

License

Open Source License

Declaration

public static List<Element> getChildElementsByTagName(Element elem, String name) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

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 elem, String name) {
        List<Element> result = new ArrayList<Element>();
        NodeList nodeList = elem.getChildNodes();
        for (int i = 0; i < nodeList.getLength(); i++) {
            Node child = nodeList.item(i);
            if (child.getNodeType() == Node.ELEMENT_NODE && child.getNodeName().equals(name)) {
                result.add((Element) child);
            }/*w  ww. j av a2s  . com*/
        }
        return result;
    }
}

Related

  1. getChildElementsByName(Element root, String tagName)
  2. getChildElementsByName(final Element parent, final String name)
  3. getChildElementsByTagName(Element ele, String childEleName)
  4. getChildElementsByTagName(Element ele, String childEleName)
  5. getChildElementsByTagName(Element ele, String childEleName, boolean localName)
  6. getChildElementsByTagName(Element element, String name)
  7. getChildElementsByTagName(Element element, String tagName)
  8. getChildElementsByTagName(Element parentElement, String childTag)
  9. getChildElementsByTagName(Element parentElement, String name)