Java XML Attribute Get getAttributeValueByName(NamedNodeMap nnm, String name)

Here you can find the source of getAttributeValueByName(NamedNodeMap nnm, String name)

Description

Searches throgh the passed NamedNodeMap for an attribute and returns it if it is found.

License

LGPL

Parameter

Parameter Description
nnm NamedNodeMap
name String

Return

String

Declaration

public static String getAttributeValueByName(NamedNodeMap nnm, String name) 

Method Source Code


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

import org.w3c.dom.*;

public class Main {
    /**//w  w  w.ja v  a2  s.  c  om
     * Searches throgh the passed NamedNodeMap for an attribute and returns it if it is found.
     * If it is not found, returns a null.
     * @param nnm NamedNodeMap
     * @param name String
     * @return String
     */
    public static String getAttributeValueByName(NamedNodeMap nnm, String name) {
        for (int i = 0; i < nnm.getLength(); i++) {
            Attr attr = (Attr) nnm.item(i);
            if (attr.getName().equalsIgnoreCase(name)) {
                return attr.getValue();
            }
        }
        return null;
    }

    /**
     * Returns the attribute value for the passed name in the passed node.
     * @param node the node to get the attribute from
     * @param name the name of the attribute
     * @return The attribute value or null if it is not found.
     */
    public static String getAttributeValueByName(Node node, String name) {
        return getAttributeValueByName(node.getAttributes(), name);
    }
}

Related

  1. getAttributeValueAsInteger(Node node, String attributeName, Integer defaultValue)
  2. getAttributeValueAsLong(final Element el, final String attrName, final long defaultVal)
  3. getAttributeValueAsString(Node node)
  4. getAttributeValueBoolean(Node node, String attrName)
  5. getAttributeValueByName(NamedNodeMap nnm, String name)
  6. getAttributeValueByName(Node node, String name)
  7. getAttributeValueByName(Node node, String name)
  8. getAttributeValueEmptyNull(Element e, String attributeName)
  9. getAttributeValueIgnoreCase(Element element, String attributeName)