get Attribute As Boolean from XML Element - Android XML

Android examples for XML:XML Attribute

Description

get Attribute As Boolean from XML Element

Demo Code


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

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

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

    public static String getAttribute(Element e, String name) {
        if (e.getAttribute(name) == null)
            return "";
        return e.getAttribute(name);
    }
}

Related Tutorials