Java XML Attribute Get getAttributeValueOrNull(NamedNodeMap attributes, String attributeName)

Here you can find the source of getAttributeValueOrNull(NamedNodeMap attributes, String attributeName)

Description

Given a list of attributes (from an XML element) and the particular attribute we are concerned with, return it's value.

License

Apache License

Parameter

Parameter Description
attributes the map of attributes
attributeName the particular attribute whose value will be returned.

Return

the value that corresponds to the attribute name provided.

Declaration

private static String getAttributeValueOrNull(NamedNodeMap attributes, String attributeName) 

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  . ja  v  a2s.  co  m*/
     * Given a list of attributes (from an XML element) and the particular attribute we are concerned with,
     * return it's value. If there is no value, return NULL>
     *
     * @param attributes    the map of attributes
     * @param attributeName the particular attribute whose value will be returned.
     * @return the value that corresponds to the attribute name provided.
     */
    private static String getAttributeValueOrNull(NamedNodeMap attributes, String attributeName) {
        String returnValue = null;
        Node namedItem = attributes.getNamedItem(attributeName);
        if (namedItem != null) {
            returnValue = namedItem.getNodeValue();
        }
        return returnValue;
    }
}

Related

  1. getAttributeValueByName(Node node, String name)
  2. getAttributeValueEmptyNull(Element e, String attributeName)
  3. getAttributeValueIgnoreCase(Element element, String attributeName)
  4. getAttributeValueNS(@Nonnull final Element aElement, @Nullable final String sNamespaceURI, @Nonnull final String sAttrName, @Nullable final String sDefault)
  5. getAttributeValueNS(Element element, String namespace, String attrName)
  6. getAttributeValuePair(Node node)
  7. getAttributeValues(Element el)
  8. getAttributeValues(Node node, String nodeName, String attrName)
  9. getAttributeWithInheritance(Element element, String attributeName)