get XML Node List By Name - Android XML

Android examples for XML:XML Node

Description

get XML Node List By Name

Demo Code


//package com.java2s;

import java.util.List;

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

public class Main {
    public static List<Node> getNodeListByName(Node node, String name,
            List<Node> finalNodeList) {
        NodeList nodeList = node.getChildNodes();
        System.out.println("child node name: " + node.getNodeName());
        if (nodeList == null)
            return null;

        for (int i = 0; i < nodeList.getLength(); i++) {
            Node candNode = nodeList.item(i);
            if (candNode.getNodeName().equals(name)) {
                finalNodeList.add(candNode);
            }/*from w ww. j a v a2s.  c  o  m*/

            getNodeListByName(nodeList.item(i), name, finalNodeList);

        }
        return finalNodeList;
    }
}

Related Tutorials