get XML Element As Boolean - Android XML

Android examples for XML:XML Element

Description

get XML Element As Boolean

Demo Code


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

public class Main {
    public static Boolean getElementAsBoolean(Element e, String name) {
        return getElementAsBoolean(e, name, false);
    }/* w w w  .j  a  v a 2 s  . co m*/

    public static Boolean getElementAsBoolean(Element e, String name,
            Boolean dft) {
        if (getElement(e, name) == null)
            return dft;
        else
            return Boolean.parseBoolean(getElement(e, name));
    }

    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