get XML Element from DOM Node - Android XML

Android examples for XML:DOM

Description

get XML Element from DOM Node

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 getNode(final Node node, final String strTagName) {
        return getNode(node.getChildNodes(), strTagName);
    }/*from   w  w w  .  ja  va  2  s. c o m*/

    public static Element getNode(final NodeList nodes,
            final String strTagName) {
        for (int i = 0; i < nodes.getLength(); ++i) {
            final Node node = nodes.item(i);

            if (node instanceof Element
                    && node.getNodeName().equals(strTagName)) {
                return (Element) node;
            }
        } // end for

        return null;
    }
}

Related Tutorials