find Child XML Element - Android XML

Android examples for XML:XML Child Element

Description

find Child XML Element

Demo Code


//package com.java2s;
import org.w3c.dom.Element;

public class Main {
    public static Element findChildElement(Element parent, String name) {
        if (parent == null) {
            return null;
        }/* ww  w .j a v  a  2  s .c om*/
        org.w3c.dom.Node ret = parent.getFirstChild();
        while (ret != null
                && (!(ret instanceof Element) || !ret.getNodeName().equals(
                        name))) {
            ret = ret.getNextSibling();
        }
        return (Element) ret;
    }
}

Related Tutorials