Java XML Attribute from Node getFloatAttribute(Node node, String name, float defVal)

Here you can find the source of getFloatAttribute(Node node, String name, float defVal)

Description

get Float Attribute

License

Open Source License

Declaration

public static float getFloatAttribute(Node node, String name,
            float defVal) 

Method Source Code

//package com.java2s;

import org.w3c.dom.Node;

public class Main {
    public static float getFloatAttribute(Node node, String name) {
        return Float.parseFloat(getAttribute(node, name, "0"));
    }/*from  w  ww .j a va 2 s.co  m*/

    public static float getFloatAttribute(Node node, String name,
            float defVal) {
        String att = getAttribute(node, name);
        if (att == null)
            return defVal;
        return Float.parseFloat(att);
    }

    /**
     * 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. generateIds(Node root, String attrName)
  2. getALLAttribute(final Node iNode)
  3. getFloatAttribute(Node node, String name, float defVal)
  4. getIntAttr(Node node, String attrName)
  5. getIntAttribute(Node n, String s)
  6. getIntAttribute(Node node, String attr)