get First Child XML Element - Android XML

Android examples for XML:XML Element

Description

get First Child XML Element

Demo Code


//package com.java2s;

import org.w3c.dom.Element;

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

public class Main {
    public static Element getFirstChildElement(Element element) {
        Element childElement = null;
        NodeList nodeList = element.getChildNodes();

        for (int i = 0; i < nodeList.getLength(); i++) {
            Node node = nodeList.item(i);
            if (node.getNodeType() == Element.ELEMENT_NODE) {
                childElement = (Element) node;
                break;
            }/*from  w w w.  j a va  2 s . co  m*/
        }

        return childElement;
    }
}

Related Tutorials