Get the first Element from Node List - Android XML

Android examples for XML:XML Node List

Description

Get the first Element from Node List

Demo Code


//package com.java2s;

import org.w3c.dom.Element;

import org.w3c.dom.NodeList;

public class Main {
    /**//from   ww  w. jav  a  2s  . com
     * @param list
     * @return
     */
    public static Element firstElement(NodeList list) {
        for (int i = 0; i < list.getLength(); i++) {
            if (list.item(i) instanceof Element) {
                return (Element) list.item(i);
            }
        }

        return null;
    }
}

Related Tutorials