get Child Int from XML Node - Android XML

Android examples for XML:XML Node

Description

get Child Int from XML Node

Demo Code



public class Main{
    /*from   w  w w. ja va  2 s . c  o m*/
    public static int getChildInt(Node node, String childNodeName) {
        String txt = getChildText(node, childNodeName);
        if (txt == null || txt.length() == 0) {
            return 0;
        } else {
            return Integer.parseInt(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