Android Utililty Methods XML Node Attribute Get

List of utility methods to do XML Node Attribute Get

Description

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

Method

StringgetAttrOfName(Node node, String string)
get Attr Of Name
NamedNodeMap attributes = node.getAttributes();
Node namedItem = attributes.getNamedItem(string);
if (namedItem == null) {
    return null;
return namedItem.getNodeValue();
StringgetAttribute(Node node, String name)
Extracts from node the attribute with the specified name.
if (node == null)
    return null;
Node attribute = node.getAttributes().getNamedItem(name);
return (attribute == null) ? null : attribute.getNodeValue().trim();
StringgetAttributeValue(Node node, String attributeName)
get Attribute Value
Node n = node.getAttributes().getNamedItem(attributeName);
if (n == null)
    return null;
else
    return n.getTextContent();
StringgetAttributeValue(Node node, String attributeName)
get Attribute Value
if (node == null || attributeName == null) {
    return null;
Node attrNode = node.getAttributes().getNamedItem(attributeName);
return attrNode != null ? attrNode.getNodeValue() : null;
IntegergetAttributeValueAsInt(Node node, String attributeName)
get Attribute Value As Int
if (node == null || attributeName == null) {
    return null;
try {
    return Integer.valueOf(Integer.parseInt(getAttributeValue(node,
            attributeName)));
} catch (NumberFormatException e) {
    return null;
...
StringgetElementAttr(Node element, String attrName)
get Element Attr
if (element.getAttributes() != null) {
    for (int i = 0; i < element.getAttributes().getLength(); i++) {
        Node child = element.getAttributes().item(i);
        if (child.getNodeName().equals(attrName)) {
            return child.getNodeValue();
return null;
StringgetElementAttr(Node element, String attrName)
get Element Attr
for (int i = 0; i < element.getAttributes().getLength(); i++) {
    Node child = element.getAttributes().item(i);
    if (child.getNodeName().equals(attrName)) {
        return child.getNodeValue();
return null;
intgetElementIntAttr(Node element, String attrName)
get Element Int Attr
String attrValue = getElementAttr(element, attrName);
if (attrValue != null) {
    return Integer.parseInt(attrValue);
return 0;
intgetElementIntAttr(Node element, String attrName)
get Element Int Attr
String attrValue = getElementAttr(element, attrName);
if (attrValue != null) {
    return Integer.parseInt(attrValue);
return 0;
ObjectgetEnumAttribute(Node archiveNode, String attrName, Object[] values, Object defaultValue)
Retrieve an attribute which value must match one of the given enums using a case-insensitive name match.
Node attr = archiveNode.getAttributes().getNamedItem(attrName);
if (attr != null) {
    String found = attr.getNodeValue();
    for (Object value : values) {
        if (value.toString().equalsIgnoreCase(found)) {
            return value;
return defaultValue;