get Attribute from XML Node by name - Java XML

Java examples for XML:XML Node

Description

get Attribute from XML Node by name

Demo Code


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

public class Main {
    public static String getAttribute(Node node, String name) {
        NamedNodeMap map = node.getAttributes();
        if (map != null && map.getNamedItem(name) != null) {
            return map.getNamedItem(name).getNodeValue();
        }//from w w w.  ja v  a  2s .c o m
        return null;
    }
}

Related Tutorials