get Attribute from XML Node by attribute name - Java XML

Java examples for XML:XML Attribute

Description

get Attribute from XML Node by attribute name

Demo Code


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

public class Main {
    public static String getAttribute(Node node, String name) {
        if (node == null) {
            return null;
        }// w  ww . jav  a2  s.c  om

        Node val = node.getAttributes().getNamedItem(name);

        if (val == null) {
            return null;
        }

        return val.getNodeValue();
    }
}

Related Tutorials