Android XML Node Value Get GetBooleanValue(Node item)

Here you can find the source of GetBooleanValue(Node item)

Description

Get Boolean Value

Declaration

public static boolean GetBooleanValue(Node item) throws Exception 

Method Source Code

//package com.java2s;

import org.w3c.dom.*;

public class Main {
    public static boolean GetBooleanValue(Node item) throws Exception {
        String asString = GetStringValue(item);
        if (asString.compareTo("0") == 0
                || asString.compareToIgnoreCase("false") == 0)
            return false;
        else if (asString.compareTo("1") == 0
                || asString.compareToIgnoreCase("true") == 0)
            return true;
        else//from   w  w w.  j a v a  2  s . c  o  m
            throw new Exception(
                    String.format(
                            "The value '%s' could not be recognised as valid Boolean value.",
                            asString));
    }

    public static String GetStringValue(Node item) throws Exception {
        if (item instanceof Element) {
            Node node = item.getFirstChild();
            if (node != null)
                return node.getNodeValue();
            else
                return "";
        } else
            throw new Exception(String.format("Cannot handle '%s'.",
                    item.getClass()));
    }
}

Related

  1. GetInt32Value(Node item)
  2. GetStringValue(Node item)
  3. getDoubleNodeValue(Node node)
  4. getElementValue(Node aElem)