Android Utililty Methods XML Element Attribute Get

List of utility methods to do XML Element Attribute Get

Description

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

Method

StringgetAttributeValue(Element elem, String name)
Returns the attribute value for the attribute with the specified name.
Attr attr = elem.getAttributeNodeNS(null, name);
return (attr == null) ? null : attr.getValue();
booleangetBooleanAttribute(Element el, String name)
get Boolean Attribute
String s = el.getAttribute(name);
if (s == null || "0".equals(s)) {
    return false;
if ("1".equals(s)) {
    return true;
return new Boolean(s).booleanValue();
...
intgetIntAttribute(Element el, String name)
get Int Attribute
String s = el.getAttribute(name);
if (s != null && s.length() > 0) {
    return Integer.parseInt(s);
return 0;
voidprocessAnyAttributes(Element element, Map anyAttributes)
Processes any attributes and add them into the element.
for (Map.Entry<QName, String> attribute : anyAttributes.entrySet()) {
    String localName = attribute.getKey().getLocalPart();
    String prefix = attribute.getKey().getPrefix();
    String namespace = attribute.getKey().getNamespaceURI();
    element.setAttributeNS(namespace, prefix + ":" + localName,
            attribute.getValue());
StringgetNodeAttrValue(Element parent, String nodeName, String attrName)
get Node Attr Value
try {
    return ((Element) parent.getElementsByTagName(nodeName).item(0))
            .getAttribute(attrName);
} catch (Exception e) {
    e.printStackTrace();
return null;