Java XML Child Get getChildElements(Element elem, String name)

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

Description

get Child Elements

License

Apache License

Declaration

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

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

import java.util.ArrayList;
import java.util.List;

public class Main {
    public static List<Element> getChildElements(Element elem, String name) {
        NodeList nodes = elem.getElementsByTagName(name);
        List<Element> elements = new ArrayList<Element>(nodes.getLength());
        for (int i = 0; i < nodes.getLength(); i++) {
            Node node = nodes.item(i);
            if (node.getNodeType() == Node.ELEMENT_NODE && node.getNodeName().equals(name)) {
                elements.add((Element) node);
            }/*  ww  w  .j  a  va 2  s.c  om*/
        }
        return elements;
    }
}

Related

  1. getChildElements(Element el)
  2. getChildElements(Element ele)
  3. getChildElements(Element ele)
  4. getChildElements(Element ele)
  5. getChildElements(Element ele, String childEleName)
  6. getChildElements(Element element)
  7. getChildElements(Element element)
  8. getChildElements(Element element)
  9. getChildElements(Element element)