Java XML Attribute from Node getIntAttribute(Node node, String name, int defVal)

Here you can find the source of getIntAttribute(Node node, String name, int defVal)

Description

get Int Attribute

License

Open Source License

Declaration

public static int getIntAttribute(Node node, String name, int defVal) 

Method Source Code

//package com.java2s;

import org.w3c.dom.Node;

public class Main {
    public static int getIntAttribute(Node node, String name, int defVal) {
        String att = getAttribute(node, name);
        if (att == null)
            return defVal;
        return Integer.parseInt(att);
    }/*from w  ww .  ja v  a  2s  . c o m*/

    public static int getIntAttribute(Node node, String name) {
        return Integer.parseInt(getAttribute(node, name));
    }

    /**
     * Returns an attribute of the specified tag with the name provided.
     *
     * @param node
     * @param name
     * @return The attribute if its defined, or null.
     */
    public static String getAttribute(Node node, String name, String defVal) {
        Node att = node.getAttributes().getNamedItem(name);
        return att == null ? defVal : att.getNodeValue();
    }

    public static String getAttribute(Node node, String name) {
        return getAttribute(node, name, null);
    }
}

Related

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