get Descendants from XML Node - Android XML

Android examples for XML:XML Node

Description

get Descendants from XML Node

Demo Code

/*/*  www  .j av  a  2 s .c  om*/
 * XmlUtil.java
 *
 * (c) 2009  The Echo Nest
 * See "license.txt" for terms
 *
 *
 */
//package com.java2s;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

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

public class Main {
    public static List<Node> getDescendants(Node node, String nodeName)
            throws IOException {
        List<Node> childList = new ArrayList<Node>();
        NodeList children = node.getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            Node child = children.item(i);
            if (child.getNodeName().equals(nodeName)) {
                childList.add(child);
            }
        }
        return childList;
    }
}

Related Tutorials