Parse Int from XML Element text content - Android XML

Android examples for XML:XML Element

Description

Parse Int from XML Element text content

Demo Code


import java.util.UUID;
import java.util.logging.Level;
import org.w3c.dom.Element;

public class Main{
    public static int ParseInt(Element e) {
        int value = 0;
        try {/*www. jav  a 2 s.  c o m*/
            value = Integer.parseInt(e.getTextContent().trim());
        } catch (NumberFormatException ex) {
            Log.log("Preferences.loadXMLFile(): An Exception occured while parsing the integer '"
                    + e.getNodeName()
                    + "'. value="
                    + e.getTextContent().trim(), Level.INFO);
        }
        return value;
    }
}

Related Tutorials