Java XML Attribute Get getAttributeValue(Element elem, String name)

Here you can find the source of getAttributeValue(Element elem, String name)

Description

Returns the attribute value for the attribute with the specified name.

License

Apache License

Parameter

Parameter Description
elem the element containing the attribute
name the name of the attribute

Return

the attribute value (may be null if unspecified)

Declaration

public static String getAttributeValue(Element elem, String name) 

Method Source Code

//package com.java2s;
/* NOTICE: This file has been changed by Plutext Pty Ltd for use in docx4j.
 * The package name has been changed; there may also be other changes.
 * //from w  w w. j a va2s. c o  m
 * This notice is included to meet the condition in clause 4(b) of the License. 
 */

import org.w3c.dom.Attr;

import org.w3c.dom.Element;

public class Main {
    /**
     * Returns the attribute value for the attribute with the specified name.
     * Returns null if there is no such attribute, or 
     * the empty string if the attribute value is empty.
     *
     * <p>This works around a limitation of the DOM
     * <code>Element.getAttributeNode</code> method, which does not distinguish
     * between an unspecified attribute and an attribute with a value of
     * "" (it returns "" for both cases).
     *
     * @param elem the element containing the attribute
     * @param name the name of the attribute
     * @return the attribute value (may be null if unspecified)
     */
    public static String getAttributeValue(Element elem, String name) {
        Attr attr = elem.getAttributeNodeNS(null, name);
        return (attr == null) ? null : attr.getValue();
    }
}

Related

  1. getAttributeValue(Element e, String name)
  2. getAttributeValue(Element el, String attributeName)
  3. getAttributeValue(Element el, String attributeName)
  4. getAttributeValue(Element el, String attrName)
  5. getAttributeValue(Element ele, String attrName)
  6. getAttributeValue(Element element, String attr)
  7. getAttributeValue(Element element, String attributeName)
  8. getAttributeValue(Element element, String attributeName, String namespaceURI)
  9. getAttributeValue(Element element, String attrName)