Java XML Child Get getChildElements(final Element elem)

Here you can find the source of getChildElements(final Element elem)

Description

get Child Elements

License

Open Source License

Declaration

public static List<Element> getChildElements(final Element elem) 

Method Source Code

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

import java.util.List;

import org.w3c.dom.Element;

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

import com.google.common.collect.Lists;

public class Main {
    public static List<Element> getChildElements(final Element elem) {
        final NodeList list = elem.getChildNodes();
        final List<Element> result = Lists.newArrayList();

        for (int i = 0; i < list.getLength(); i++) {
            final Node node = list.item(i);
            if (node instanceof Element) {
                result.add((Element) node);
            }//from  w  w  w . j  a v a 2s.c o  m
        }

        return result;
    }

    public static List<Node> getChildNodes(final Node node) {
        final NodeList list = node.getChildNodes();
        final List<Node> result = Lists.newArrayList();

        for (int i = 0; i < list.getLength(); i++) {
            final Node child = list.item(i);
            result.add(child);
        }

        return result;
    }
}

Related

  1. getChildElements(Element parentElement)
  2. getChildElements(Element parentElement)
  3. getChildElements(Element parentElement, String childElementTagName)
  4. getChildElements(Element parentNode)
  5. getChildElements(Element root, String name, boolean mandatory)
  6. getChildElements(final Element element)
  7. getChildElements(final Element element, final String localName)
  8. getChildElements(final Element element, final String namespace, final String tagName)
  9. getChildElements(final Element elm)