Java XML Attribute Get getAttributeAsString(NamedNodeMap attributes, String name)

Here you can find the source of getAttributeAsString(NamedNodeMap attributes, String name)

Description

Get an attribute's value and return an empty string, of the attribute is not specified

License

Open Source License

Parameter

Parameter Description
attributes Attributes node
name Name of the attribute

Return

Attributes value

Declaration

public static String getAttributeAsString(NamedNodeMap attributes, String name) 

Method Source Code

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

import org.w3c.dom.Attr;
import org.w3c.dom.NamedNodeMap;

public class Main {
    /**/*from   ww  w.  j a  v  a 2 s .c o  m*/
     * Get an attribute's value and return an empty string, of the attribute is
     * not specified
     * 
     * @param attributes
     *            Attributes node
     * @param name
     *            Name of the attribute
     * @return Attributes value
     */
    public static String getAttributeAsString(NamedNodeMap attributes, String name) {
        Attr attribute;
        String value = ""; //$NON-NLS-1$
        attribute = (Attr) attributes.getNamedItem(name);
        if (attribute != null) {
            value = attribute.getValue();
        }
        return value;
    }
}

Related

  1. getAttributeAsBoolean(Element element, String attrName, boolean defValue)
  2. getAttributeAsBoolean(Element element, String name)
  3. getAttributeAsBoolean(NamedNodeMap map, String name)
  4. getAttributeAsInteger(Element element, String attrName, Integer defValue)
  5. getAttributeAsLong(Element element, String attrName, Long defValue)
  6. getAttributeAsString(XMLStreamReader reader, String name)
  7. getAttributeAsURIString(XMLStreamReader reader, String name)
  8. getAttributeBoolean(Element aElement, String aAttributeName)
  9. getAttributeBoolean(Element el, String label)