find Element by XML Element name - Android XML

Android examples for XML:XML Element

Description

find Element by XML Element name

Demo Code


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

public class Main {
    public static Element findElement(Element root, String elementName) {
        return findElement(root, elementName, 0);
    }//w w  w.j  av  a 2s .  co m

    public static Element findElement(Element root, String elementName,
            int index) {
        NodeList nodeList = root.getElementsByTagName(elementName);

        if (nodeList != null && nodeList.getLength() > index) {
            return (Element) nodeList.item(index);
        }

        return null;
    }
}

Related Tutorials