Android XML Node Attribute Get getAttributeValueAsInt(Node node, String attributeName)

Here you can find the source of getAttributeValueAsInt(Node node, String attributeName)

Description

get Attribute Value As Int

Declaration

static Integer getAttributeValueAsInt(Node node, String attributeName) 

Method Source Code

//package com.java2s;

import org.w3c.dom.Node;

public class Main {
    static Integer getAttributeValueAsInt(Node node, String attributeName) {
        if (node == null || attributeName == null) {
            return null;
        }/*from   www .  j a  v a  2s .  com*/
        try {
            return Integer.valueOf(Integer.parseInt(getAttributeValue(node,
                    attributeName)));
        } catch (NumberFormatException e) {
            return null;
        }
    }

    static String getAttributeValue(Node node, String attributeName) {
        if (node == null || attributeName == null) {
            return null;
        }
        Node attrNode = node.getAttributes().getNamedItem(attributeName);
        return attrNode != null ? attrNode.getNodeValue() : null;
    }

    static String getNodeValue(Node node) {
        return (node == null || node.getFirstChild() == null || node
                .getFirstChild().getNodeValue() == null) ? null : node
                .getFirstChild().getNodeValue().trim();
    }
}

Related

  1. getAttrOfName(Node node, String string)
  2. getAttribute(Node node, String name)
  3. getAttributeValue(Node node, String attributeName)
  4. getAttributeValue(Node node, String attributeName)
  5. getElementAttr(Node element, String attrName)
  6. getElementAttr(Node element, String attrName)
  7. getElementIntAttr(Node element, String attrName)
  8. getElementIntAttr(Node element, String attrName)