get Node Value from XML Element - Android XML

Android examples for XML:XML Node

Description

get Node Value from 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 String getNodeValue(Element element, String name,
            int index) {
        NodeList list = element.getElementsByTagName(name);
        if (list == null)
            return null;
        Node node = list.item(index).getFirstChild();
        if (node == null)
            return null;
        return node.getNodeValue().trim();
    }/*from   w w  w . j a va 2s.com*/

    public static String getNodeValue(Node element, String name) {
        return getNodeValue((Element) element, name, 0);
    }

    public static String getNodeValue(Element element, String name) {
        return getNodeValue(element, name, 0);
    }
}

Related Tutorials