Java XML Attribute Get getAttribute(Node currentNode, String attributeName)

Here you can find the source of getAttribute(Node currentNode, String attributeName)

Description

Gets the attribute value for a Node given the attribute name

License

Open Source License

Parameter

Parameter Description
currentNode a parameter
attributeName a parameter

Return

the attribute value

Declaration

public static String getAttribute(Node currentNode, String attributeName) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    /**/*w w  w. j av a 2s  .com*/
     * Gets the attribute value for a Node given the attribute name
     * 
     * @param currentNode
     * @param attributeName
     * @return the attribute value
     */
    public static String getAttribute(Node currentNode, String attributeName) {
        NamedNodeMap attrs = currentNode.getAttributes();
        return attrs.getNamedItem(attributeName).getNodeValue().trim();
    }
}

Related

  1. getAttribute(NamedNodeMap map, String name)
  2. getAttribute(NamedNodeMap namedNodeMap, String name)
  3. getAttribute(NamedNodeMap ruleAttributes, String attributeName)
  4. getAttribute(Node aNode, String attributeName)
  5. getAttribute(Node attrNode)
  6. getAttribute(Node element, String attName)
  7. getAttribute(Node element, String name, String dflt)
  8. getAttribute(Node iNode, String iAttributeName)
  9. getAttribute(Node n, String attr)