Java XML Attribute from Node getIntAttribute(Node node, String attributeName, int defaultValue)

Here you can find the source of getIntAttribute(Node node, String attributeName, int defaultValue)

Description

get Int Attribute

License

Open Source License

Declaration

public static int getIntAttribute(Node node, String attributeName,
            int defaultValue) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import org.w3c.dom.Node;

public class Main {
    public static int getIntAttribute(Node node, String attributeName,
            int defaultValue) {
        String value = getAttribute(node, attributeName);
        if (value == null) {
            return defaultValue;
        }// w  w w .  ja  v  a2 s  .  c o  m
        return Integer.parseInt(value);
    }

    public static int getIntAttribute(Node node, String attributeName) {
        return getIntAttribute(node, attributeName, 0);
    }

    public static String getAttribute(Node node, String attributeName) {
        Node n = node.getAttributes().getNamedItem(attributeName);
        if (n != null) {
            return n.getNodeValue();
        } else {
            return null;
        }
    }
}

Related

  1. getFloatAttribute(Node node, String name, float defVal)
  2. getFloatAttribute(Node node, String name, float defVal)
  3. getIntAttr(Node node, String attrName)
  4. getIntAttribute(Node n, String s)
  5. getIntAttribute(Node node, String attr)
  6. getIntAttribute(Node node, String name, int defVal)
  7. getIntAttributeRequired(Node node, String attributeName)
  8. getIntAttributeValue(Node node, String attribute)
  9. getIntAttrId(Node aNode, String aAttrName)