get XML Attribute Value - Java XML

Java examples for XML:XML Attribute

Description

get XML Attribute Value

Demo Code


//package com.java2s;

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

public class Main {
    /**/*  ww  w  . ja va  2 s .com*/
     * @param node
     * @param attributeKey
     * @return
     */
    public static String getAttributeValue(Node node, String attributeKey) {
        NamedNodeMap attributes = node.getAttributes();
        Node attribute = attributes.getNamedItem(attributeKey);
        if (attribute == null) {
            return null;
        }
        return attribute.getNodeValue();
    }
}

Related Tutorials