get Attribute As Float from XML Element - Android XML

Android examples for XML:XML Attribute

Description

get Attribute As Float from XML Element

Demo Code


//package com.java2s;
import org.w3c.dom.Element;

public class Main {
    public static Float getAttribAsFloat(Element e, String name, Float dft) {
        String num = getAttribute(e, name);
        return num.equals("") ? dft : Float.parseFloat(num);
    }/*  w  w w  .j  av a2s .c om*/

    public static String getAttribute(Element e, String name) {
        if (e.getAttribute(name) == null)
            return "";
        return e.getAttribute(name);
    }
}

Related Tutorials