Java XML Attribute from Element getFloatAttribute(String name, Element el)

Here you can find the source of getFloatAttribute(String name, Element el)

Description

Gets the value of the DOM element's attribute with the given name as a Float, or null if the value is not a float.

License

Open Source License

Declaration

public static Float getFloatAttribute(String name, Element el) 

Method Source Code

//package com.java2s;

import org.w3c.dom.*;

public class Main {
    /**//from  w w w .jav a2 s  .com
     * Gets the value of the DOM element's attribute with the given name
     * as a Float, or null if the value is not a float.
     */
    public static Float getFloatAttribute(String name, Element el) {
        return stringToFloat(getAttribute(name, el));
    }

    private static Float stringToFloat(String value) {
        if (value == null)
            return null;
        try {
            return new Float(value);
        } catch (NumberFormatException exc) {
            return null;
        }
    }

    /**
     * Gets the value of the given DOM element's attribute
     * with the specified name.
     */
    public static String getAttribute(String name, Element el) {
        if (name == null || el == null)
            return null;
        if (!el.hasAttribute(name))
            return null;
        return el.getAttribute(name);
    }
}

Related

  1. getElementStringValue(Element element, String attribute)
  2. getElementTextByAttr(Element modsroot, String nodename, String attrname, String attrvalue)
  3. getElementValues(final String elementName, final String attributeValue, final InputStream is)
  4. getFirstAttribute(Element elem, String name, String attrName)
  5. getFloatAttribute(Element element, String name)
  6. getHeadAttr(Element annotU, String attrName)
  7. getIdAttribute(Element domElement)
  8. getIdAttributeValue(Element elem, String name)
  9. getIntAttr(Element elem, String attName)