get XML Element Attribute - Android XML

Android examples for XML:XML Attribute

Description

get XML Element Attribute

Demo Code


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

public class Main {
    public static String getElementAttr(Node element, String attrName) {
        for (int i = 0; i < element.getAttributes().getLength(); i++) {
            Node child = element.getAttributes().item(i);
            if (child.getNodeName().equals(attrName)) {
                return child.getNodeValue();
            }/* w w w  .j a  va  2 s . co m*/
        }

        return null;
    }
}

Related Tutorials