Java XML Child Get getChildElements(Element element)

Here you can find the source of getChildElements(Element element)

Description

get single element by tag name

License

Apache License

Parameter

Parameter Description
element a parameter
tag a parameter

Declaration

public static List<Element> getChildElements(Element element) 

Method Source Code

//package com.java2s;
//License from project: Apache 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 {
    /**//from  w ww . j  av a  2  s . com
     * get single element by tag name
     * @param element
     * @param tag
     * @return
     */
    public static List<Element> getChildElements(Element element) {
        List<Element> elems = new ArrayList<Element>();
        NodeList list = element.getChildNodes();
        for (int i = 0; i < list.getLength(); i++) {
            Node node = list.item(i);
            if (node instanceof Element) {
                Element e = (Element) node;
                elems.add(e);
            }
        }
        return elems;
    }
}

Related

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