get Attribute Value from Node - Java XML

Java examples for XML:XML Attribute

Description

get Attribute Value from Node

Demo Code


//package com.java2s;

import org.w3c.dom.Node;

public class Main {
    public static String getAttributeValue(Node node, String attributeName) {
        if (node == null || node.getAttributes() == null
                || node.getAttributes().getNamedItem(attributeName) == null) {
            return null;
        }/*from  w w w  . j a v  a  2  s  .  c  o m*/
        return node.getAttributes().getNamedItem(attributeName)
                .getNodeValue();
    }
}

Related Tutorials