Java Utililty Methods XML Attribute Get

List of utility methods to do XML Attribute Get

Description

The list of methods to do XML Attribute Get are organized into topic(s).

Method

StringgetAttributeValueAsString(Node node)
Gets the attribute value as string.
if (node != null) {
    return node.getNodeValue();
return null;
booleangetAttributeValueBoolean(Node node, String attrName)
Returns boolean value of the named attribute of the node.
String value = getAttributeValue(node, attrName);
return "true".equalsIgnoreCase(value) || "1".equals(value);
StringgetAttributeValueByName(NamedNodeMap nnm, String name)
Searches throgh the passed NamedNodeMap for an attribute and returns it if it is found.
if (nnm == null)
    return null;
for (int i = 0; i < nnm.getLength(); i++) {
    Attr attr = (Attr) nnm.item(i);
    if (attr.getName().equalsIgnoreCase(name)) {
        return attr.getValue();
return null;
StringgetAttributeValueByName(NamedNodeMap nnm, String name)
Searches throgh the passed NamedNodeMap for an attribute and returns it if it is found.
for (int i = 0; i < nnm.getLength(); i++) {
    Attr attr = (Attr) nnm.item(i);
    if (attr.getName().equalsIgnoreCase(name)) {
        return attr.getValue();
return null;
StringgetAttributeValueByName(Node node, String name)
Returns the attribute value for the passed name in the passed node.
return getAttributeValueByName(node.getAttributes(), name);
StringgetAttributeValueByName(Node node, String name)
Returns the attribute value for the passed name in the passed node.
return getAttributeValueByName(node.getAttributes(), name);
StringgetAttributeValueEmptyNull(Element e, String attributeName)
This function is much like getAttribute, but returns null, not "", for a nonexistent attribute.
Attr node = e.getAttributeNode(attributeName);
if (node == null) {
    return null;
return node.getValue();
StringgetAttributeValueIgnoreCase(Element element, String attributeName)
Gets the value of DOM attribute of element with the given name It returns the first attribute value that matches the name, regardless the case.
Attr a = getAttributeIgnoreCase(element, attributeName);
if (a != null) {
    a.getValue();
return null;
StringgetAttributeValueNS(@Nonnull final Element aElement, @Nullable final String sNamespaceURI, @Nonnull final String sAttrName, @Nullable final String sDefault)
The latest version of XercesJ 2.9 returns an empty string for non existing attributes.
final Attr aAttr = aElement.getAttributeNodeNS(sNamespaceURI, sAttrName);
return aAttr == null ? sDefault : aAttr.getValue();
StringgetAttributeValueNS(Element element, String namespace, String attrName)
Get attribute value.
String attrValue = null;
Attr attr = null;
if ((attr = element.getAttributeNodeNS(namespace, attrName)) != null) {
    attrValue = attr.getValue().trim();
return attrValue;