Java XML Attribute Read readFloat(Node node, String attributeName, float def)

Here you can find the source of readFloat(Node node, String attributeName, float def)

Description

read Float

License

Apache License

Declaration

public static float readFloat(Node node, String attributeName, float def) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import org.w3c.dom.Node;

public class Main {
    public static float readFloat(Node node, String attributeName, float def) {
        try {//from   w  w  w. j av a  2  s .  co  m
            return Float.parseFloat(node.getAttributes().getNamedItem(attributeName).getNodeValue());
        } catch (Exception ex) {
            return def;
        }
    }

    public static float parseFloat(String f, float def) {
        if (f == null) {
            return def;
        } else {
            try {
                return Float.parseFloat(f);
            } catch (NumberFormatException ex) {
                return 0;
            }
        }
    }

    public static float parseFloat(String f) {
        if (f == null) {
            return 0;
        } else {
            try {
                return Float.parseFloat(f);
            } catch (NumberFormatException ex) {
                return 0;
            }
        }
    }
}

Related

  1. readAttribute(Node node, String attribute, String defaultValue)
  2. readAttributeWithPrefix(Node node, String attributePrefix, String defaultValue)
  3. readBoolAttr(Element element, String attributeName)
  4. readBooleanAttribute(Element elem, String name, boolean defaultValue)
  5. readBooleanAttributeElement(final XMLStreamReader reader, final String attributeName)
  6. readFloatAttribute(XMLStreamReader reader, String attributeName)
  7. readInt(Node node, String attributeName, int def)
  8. readIntAttr(Element element, String attributeName, int defaultValue)
  9. readIntegerAttribute(Element elem, String name, int defaultValue)