get Attribute Boolean from XML Node by name - Java XML

Java examples for XML:XML Attribute

Description

get Attribute Boolean from XML Node by name

Demo Code


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

public class Main {
    public static boolean getAttributeBoolean(Node node, String name) {
        return Boolean.parseBoolean(getAttribute(node, name));
    }//w ww.java  2  s.  c o m

    public static String getAttribute(Node node, String name) {
        if (node == null) {
            return null;
        }

        Node val = node.getAttributes().getNamedItem(name);

        if (val == null) {
            return null;
        }

        return val.getNodeValue();
    }
}

Related Tutorials