get Child from XML Node By tag - Android XML

Android examples for XML:XML Child Element

Description

get Child from XML Node By tag

Demo Code


//package com.java2s;

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

public class Main {
    public static Node getChild(Node node, String tag) {
        if (node == null) {
            return null;
        }//from   ww  w.  j a  v  a  2  s  . com
        NodeList childNodes = node.getChildNodes();
        if (childNodes == null) {
            return null;
        }
        for (int i = 0; i < childNodes.getLength(); i++) {
            Node item = childNodes.item(i);
            if (item != null) {
                String name = item.getNodeName();
                if (tag.equalsIgnoreCase(name)) {
                    return item;
                }
            }
        }
        return null;
    }
}

Related Tutorials