Java XML Attribute Get getBooleanAttribute(Node targetElem, String keyName, boolean defaultValue)

Here you can find the source of getBooleanAttribute(Node targetElem, String keyName, boolean defaultValue)

Description

get Boolean Attribute

License

Open Source License

Declaration

public static boolean getBooleanAttribute(Node targetElem,
            String keyName, boolean defaultValue) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2015 Bruno Medeiros and other Contributors.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/* ww  w .j  av  a  2  s .c o  m*/
 *     Bruno Medeiros - initial API and implementation
 *******************************************************************************/

import org.w3c.dom.Node;

public class Main {
    public static boolean getBooleanAttribute(Node targetElem,
            String keyName, boolean defaultValue) {
        String enabledStr = getAttribute(targetElem, keyName, null);
        if (enabledStr == null) {
            return defaultValue;
        }
        return Boolean.parseBoolean(enabledStr);
    }

    public static String getAttribute(Node targetElem, String keyName,
            String defaultValue) {
        Node attribute = targetElem.getAttributes().getNamedItem(keyName);
        if (attribute == null) {
            return defaultValue;
        }
        return attribute.getTextContent();
    }
}

Related

  1. getBooleanAttribute(Element element, String attributeName)
  2. getBooleanAttribute(Element element, String key, boolean defValue)
  3. getBooleanAttribute(Element element, String name)
  4. getBooleanAttribute(Element element, String name, boolean defaultValue)
  5. getBooleanAttribute(Node n, String attributeName)
  6. getBooleanAttributeByName(Node content, String attributeName, boolean defaultTrue)
  7. getBooleanAttributeOption(final Element configuration, final String option, boolean defaultValue)
  8. getBooleanAttributeOptional(Node node, String attributeName, Boolean valueIfEmpty)
  9. getBooleanAttributeRequired(Node node, String attributeName)