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 node, String s)
get Node Attribute
NamedNodeMap attributes = node.getAttributes();
for (int k = 0; k < attributes.getLength(); k++) {
    Node nodeAttr = attributes.item(k);
    if (nodeAttr.getNodeName().equals(s)) {
        return nodeAttr.getNodeValue();
return null;
...
StringgetNodeAttribute(Node QueryNode, String AttrName)
return an attruibte value from a Node
NamedNodeMap attrs = QueryNode.getAttributes();
if (attrs == null)
    return (null);
Node Value = attrs.getNamedItem(AttrName);
if (Value == null)
    return (null);
return (Value.getNodeValue());
StringgetNodeAttribute(Node thisNode, String key)
Utility method to look for any key=value attribute for a Node and returns null if the attribute does not exist or contains the empty string.
if (null == thisNode) {
    return null;
NamedNodeMap attributes = thisNode.getAttributes();
if (null == attributes) {
    return null;
Node node = attributes.getNamedItem(key);
...
intgetNodeAttributeAsInt(Node node, String attributeName, int defaultValue)
get Node Attribute As Int
String s = getNodeAttribute(node, attributeName);
if (null == s) {
    return defaultValue;
} else {
    return convertToInt(attributeName, s);
StringgetNodeAttributeDeep(NodeList nodelList, String nodeName, String nodeAttr)
get Node Attribute Deep
for (int i = 0; i < nodelList.getLength(); i++) {
    Node node = nodelList.item(i);
    if (node.getNodeName().equals(nodeName)) {
        return getNodeAttribute(node, nodeAttr);
    if (node.getChildNodes().getLength() > 0) {
        String result = getNodeAttributeDeep(node.getChildNodes(), nodeName, nodeAttr);
        if (result != null)
...
Comparable[]getNodeAttributes(final Node node)
get Node Attributes
return new Comparable[] { Short.valueOf(node.getNodeType()), node.getNodeName(), node.getLocalName(),
        node.getNamespaceURI(), node.getPrefix(), node.getNodeValue() };
StringgetNodeAttributesToString(Node node)
Returns in a String the attributes and values of the node.
String atributos = "";
String coma = "";
for (int j = 0; j < node.getAttributes().getLength(); j++) {
    Node atributo = node.getAttributes().item(j);
    atributos = atributos + coma + atributo.toString();
    coma = " ; ";
return atributos;
...
StringgetNodeAttributeValue(Node element, String attributeName)
Insert the method's description here.
Node tmpNode = element.getAttributes().getNamedItem(attributeName);
String tmp = null;
if (tmpNode != null)
    tmp = tmpNode.getNodeValue();
return tmp;
StringgetNodeAttributeValue(Node node, String attribute)
get Node Attribute Value
String value = null;
NamedNodeMap attributes = node.getAttributes();
Node valueNode = attributes.getNamedItem(attribute);
if (valueNode != null)
    value = valueNode.getNodeValue();
return value;
StringgetNodeAttributeValue(Node node, String attributeName)
get Node Attribute Value
NamedNodeMap attributes = node.getAttributes();
if (attributes == null)
    return null;
Node attributeValue = attributes.getNamedItem(attributeName);
return attributeValue == null ? null : attributeValue.getNodeValue();