Java Utililty Methods XML Attribute from Node

List of utility methods to do XML Attribute from Node

Description

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

Method

StringgetNodeAttribute(Node n, String as)
Returns the String that is the attribute of Node n named by attname or "" if that attribute doesn't exist.
return ((Element) n).getAttribute(as);
StringgetNodeAttribute(Node n, String attrName)
get Node Attribute
Node namedAttr = n.getAttributes().getNamedItem(attrName);
if (namedAttr != null)
    return namedAttr.getNodeValue();
else
    return null;
StringgetNodeAttribute(Node n, String name)
get Node Attribute
if (n == null)
    return null;
NamedNodeMap attr = n.getAttributes();
Node nameNode = attr.getNamedItem(name);
if (nameNode != null) {
    String name_value = getNodeValue(nameNode);
    return name_value;
} else {
...
StringGetNodeAttribute(Node node, String attributeName)
Returns the content of the specified attribute in the specified node.
Element x = (Element) node;
return x.getAttribute(attributeName);
StringgetNodeAttribute(Node node, String attributeName)
get Node Attribute
String sRetValue = null;
NamedNodeMap attributes = node.getAttributes();
if (attributes != null) {
    Node attrib = attributes.getNamedItem(attributeName);
    if (attrib != null) {
        sRetValue = attrib.getNodeValue();
return sRetValue;
StringgetNodeAttribute(Node node, String attributeName, String defaultValue)
get the attribute with the given name from the given node
NamedNodeMap attributes = node.getAttributes();
if (attributes == null)
    return defaultValue;
Node attribute = attributes.getNamedItem(attributeName);
return (attribute == null) ? defaultValue : attribute.getNodeValue();
StringgetNodeAttribute(Node node, String name)
get Node Attribute
if (node.hasAttributes()) {
    NamedNodeMap attrs = node.getAttributes();
    for (int i = 0; i < attrs.getLength(); i++) {
        Attr attribute = (Attr) attrs.item(i);
        if (attribute.getName().equals(name)) {
            return attribute.getValue();
return null;
StringgetNodeAttribute(Node node, String name)
get Node Attribute
NamedNodeMap map = node.getAttributes();
Node n = map.getNamedItem(name);
if (n != null) {
    return n.getNodeValue();
return null;
StringgetNodeAttribute(Node node, String name)
return the attribute value of an element.
if (node instanceof Element) {
    Element element = (Element) node;
    return element.getAttribute(name);
return null;
StringgetNodeAttribute(Node node, String name, String def)
get Node Attribute
return getNamedItemNodeValue(node.getAttributes(), name, def);