get XML Elements from Element - Android XML

Android examples for XML:XML Element

Description

get XML Elements from Element

Demo Code


//package com.java2s;

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> getElements(Element element) {
        List<Element> elementList = new ArrayList<Element>();
        NodeList nodeList = element.getChildNodes();
        for (int i = 0; i < nodeList.getLength(); i++) {
            Node node = nodeList.item(i);
            if (node.getNodeType() == Node.ELEMENT_NODE) {
                elementList.add((Element) node);
            }/*from  w w  w. j av a2s .c  o  m*/
        }
        return elementList;
    }
}

Related Tutorials