Java XML Attribute Get getAttributeValue(Node node, String attrName)

Here you can find the source of getAttributeValue(Node node, String attrName)

Description

Gets the value of a specific attribute attached to the given node

License

Apache License

Parameter

Parameter Description
node a parameter
attrName a parameter

Declaration

static String getAttributeValue(Node node, String attrName) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

public class Main {
    /**/*from   w  ww . java 2s .  co m*/
     * Gets the value of a specific attribute attached to the given node
     * @param node
     * @param attrName
     * @return
     */
    static String getAttributeValue(Node node, String attrName) {
        if (node == null)
            return null;
        ;
        NamedNodeMap map = node.getAttributes();
        if (map != null && map.getNamedItem(attrName) != null)
            return map.getNamedItem(attrName).getTextContent();
        else
            return null;
    }
}

Related

  1. getAttributeValue(Node node, String attributeName)
  2. getAttributeValue(Node node, String attributeName)
  3. getAttributeValue(Node node, String attributeName)
  4. getAttributeValue(Node node, String attributeName, int defaultValue)
  5. getAttributeValue(Node node, String attrName)
  6. getAttributeValue(Node node, String name)
  7. getAttributeValue(Node node, String name)
  8. getAttributeValue(Node node, String name)
  9. getAttributeValue(Node node, String name, boolean defaultValue)