get XML Node Attribute - Android XML

Android examples for XML:XML Attribute

Description

get XML Node Attribute

Demo Code


//package com.java2s;

import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;

public class Main {

    public static String getNodeAttribute(Node node, String name) {
        String value = null;//from  w  w w.j a  va 2  s .  c o m
        try {
            NamedNodeMap nodeMap = node.getAttributes();
            Node nodeAttr = nodeMap.getNamedItem(name);
            value = nodeAttr.getNodeValue();
        } catch (Exception e) {
            value = null;
        }

        return value;
    }

    public static String getNodeValue(Node node) {
        String value = "";

        try {
            if (node.getFirstChild() != null)
                value = node.getFirstChild().getNodeValue();
        } catch (Exception e) {
            value = null;
        }

        return value;
    }
}

Related Tutorials