get XML Element As Float - Android XML

Android examples for XML:XML Element

Description

get XML Element As Float

Demo Code


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

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

    public static String getElement(Element e, String name) {
        if (e.getElementsByTagName(name) == null)
            return "";
        if (e.getElementsByTagName(name).item(0) == null)
            return "";
        return e.getElementsByTagName(name).item(0).getTextContent();
    }
}

Related Tutorials