Android 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

MapextractAttributesFromTag(String tag)
Extracts all attributes from tags, for example
if (tag == null) {
    return null;
Matcher m = getMatcher(tag, " .*(?=[>])");
if (m.find() == false) {
    return null;
Map<String, String> attributes = new HashMap<String, String>();
...
StringgetAttribute(String key, Attributes attributes, Map tagCache)
get Attribute
Integer value = tagCache.get(key);
if (null == value || value.intValue() == -1) {
    return null;
} else {
    return attributes.getValue(value);
StringgetAttributesValue(Attributes attrs, String name)
get Attributes Value
for (int i = 0; i < attrs.getLength(); ++i) {
    if (attrs.getLocalName(i).equals(name)) {
        return attrs.getValue(i);
return null;
StringgetXmlAttribute(Context context, XmlResourceParser xml, String name)
get Xml Attribute
int resId = xml.getAttributeResourceValue(null, name, 0);
if (resId == 0) {
    return xml.getAttributeValue(null, name);
} else {
    return context.getString(resId);
StringgetNodeAttributeOrDefault(Node node, String name, String defaultValue)
get Node Attribute Or Default
NamedNodeMap attributes = node.getAttributes();
Node valueNode = attributes.getNamedItem(name);
String value = defaultValue;
if (valueNode != null)
    value = valueNode.getNodeValue();
return value;
StringgetNodeAttributeOrFail( Node node, String name, ExceptionType e)
get Node Attribute Or Fail
NamedNodeMap attributes = node.getAttributes();
Node valueNode = attributes.getNamedItem(name);
if (valueNode == null)
    throw e;
return valueNode.getNodeValue();
StringgetNodeAttributeOrFail( Node node, String name, T e)
Retrieves the value for a xml Node attribute or fails if not found.
NamedNodeMap attributes = node.getAttributes();
Node valueNode = attributes.getNamedItem(name);
if (valueNode == null)
    throw e;
return valueNode.getNodeValue();