get Child Float from XML Node - Android XML

Android examples for XML:XML Node

Description

get Child Float from XML Node

Demo Code



public class Main{
    //from  ww  w  .j a v a 2s .c  om
    public static float getChildFloat(Node node, String childNodeName) {
        String txt = getChildText(node, childNodeName);
        if (txt == null || txt.length() == 0) {
            return 0;
        } else {
            return Float.parseFloat(txt);
        }
    }
    
    public static String getChildText(Node node, String childNodeName) {
        Node child = node.getFirstChildrenByName(childNodeName);
        if (child != null) {
            return child.getText();
        } else {
            return null;
        }
    }
}

Related Tutorials