Java XML Attribute Get getDoubleAttribute(String name, Element el)

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

Description

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

License

Open Source License

Declaration

public static Double getDoubleAttribute(String name, Element el) 

Method Source Code

//package com.java2s;

import org.w3c.dom.*;

public class Main {
    /**/* w w w .ja  va2  s  . c  om*/
     * Gets the value of the DOM element's attribute with the given name
     * as a Double, or null if the value is not a double.
     */
    public static Double getDoubleAttribute(String name, Element el) {
        return stringToDouble(getAttribute(name, el));
    }

    private static Double stringToDouble(String value) {
        if (value == null)
            return null;
        try {
            return new Double(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. getDirectAttribute(Node node, String name)
  2. getDivHeadAttr(Element annotU, String attrName)
  3. getDoubleArrayTagAttribute(XMLStreamReader xmler, String attribute, double[] defaultValue)
  4. getDoubleAttribute(Element element, String name)
  5. getDoubleAttribute(Node n, String s)
  6. getDoubleAttributeValue(Element element, String attribute)
  7. getDoubleAttributeValue(final Element element, final String attributeName)