Java XML Attribute Get getAttribute(String key, NamedNodeMap map)

Here you can find the source of getAttribute(String key, NamedNodeMap map)

Description

Gets the attribute as a string.

License

Open Source License

Parameter

Parameter Description
key the name of the attribute.
map the named node map with the attribute key/value pairs.

Return

the attribute value or an empty string if it does not exist.

Declaration

public static String getAttribute(String key, NamedNodeMap map) 

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.  ja v  a  2s. co  m*/
     * Gets the attribute as a string.
     * @param key the name of the attribute.
     * @param map the named node map with the attribute key/value pairs.
     * @return the attribute value or an empty string if it does not exist.
     */
    public static String getAttribute(String key, NamedNodeMap map) {
        Node attr = map.getNamedItem(key);
        return attr != null ? attr.getTextContent() : "";
    }
}

Related

  1. getAttribute(Node targetElem, String keyName, String defaultValue)
  2. getAttribute(String aAttrName, Node aNode)
  3. getAttribute(String attribute, Node node)
  4. getAttribute(String attribute, Node node)
  5. getAttribute(String attribute, Node node)
  6. getAttribute(String name, Element el)
  7. getAttribute(String name, Element element)
  8. getAttribute(String name, Element firstElement, Element secondElement)
  9. getAttribute(String name, Node node)