get Node from Element by name - Android XML

Android examples for XML:XML Node

Description

get Node from Element by name

Demo Code


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

public class Main {
    public static Element getNode(Element e, String name) {
        Node n = e.getElementsByTagName(name).item(0);
        if (n == null)
            return e;
        else if (n.getNodeType() == Node.ELEMENT_NODE) {
            return (Element) n;
        } else/*from   ww  w.ja  v  a 2 s  . c  o  m*/
            return e;
    }
}

Related Tutorials