get Child Node from XML Element - Android XML

Android examples for XML:XML Child Element

Description

get Child Node from XML Element

Demo Code


//package com.java2s;
import org.w3c.dom.*; // XML objects (Element, NodeList, Node, etc)

public class Main {
    public static Node getChildNode(Element xeElement, String sTagName) {
        for (Node xnChild = xeElement.getFirstChild(); xnChild != null; xnChild = xnChild
                .getNextSibling()) {/*ww w .j a  v  a  2 s  .  c  om*/
            if ((xnChild.getNodeType() == Node.ELEMENT_NODE)
                    && (sTagName.equals(xnChild.getNodeName()))) {
                return xnChild;
            }
        }

        return null;
    }
}

Related Tutorials