Java XML Attribute from Node getNodeAttribute(Node QueryNode, String AttrName)

Here you can find the source of getNodeAttribute(Node QueryNode, String AttrName)

Description

return an attruibte value from a Node

License

Apache License

Parameter

Parameter Description
QueryNode non-null node
AttrName non-null attr name return possibly null value - null of the attribute does not exist

Declaration

public static String getNodeAttribute(Node QueryNode, String AttrName) 

Method Source Code


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

import org.w3c.dom.*;

public class Main {
    /**//from   w  w  w  .  j  av  a 2 s .  com
    * return an attruibte value from a Node
    * @param QueryNode non-null node
    * @param AttrName non-null attr name
    * return possibly null value - null of the attribute does not exist
    */
    public static String getNodeAttribute(Node QueryNode, String AttrName) {
        NamedNodeMap attrs = QueryNode.getAttributes();
        if (attrs == null)
            return (null);
        Node Value = attrs.getNamedItem(AttrName);
        if (Value == null)
            return (null);
        return (Value.getNodeValue());
    }
}

Related

  1. getNodeAttribute(Node node, String name)
  2. getNodeAttribute(Node node, String name)
  3. getNodeAttribute(Node node, String name)
  4. getNodeAttribute(Node node, String name, String def)
  5. getNodeAttribute(Node node, String s)
  6. getNodeAttribute(Node thisNode, String key)
  7. getNodeAttributeAsInt(Node node, String attributeName, int defaultValue)
  8. getNodeAttributeDeep(NodeList nodelList, String nodeName, String nodeAttr)
  9. getNodeAttributes(final Node node)