Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;

public class Main {
    /**
     * Returns the boolean value of the named attribute for the given node
     * If no such attribute exists, returns false
     */
    public static boolean getBoolValue(Node node, String name) {
        // Look for the attribute
        Node att = get_named_attribute(node, name);
        if (att != null) {
            // Return the value
            return Boolean.valueOf(att.getNodeValue()).booleanValue();
        } else {
            // No such attribute
            return false;
        }
    }

    /**
     * Returns the given attribute of a node, if it exists
     * Otherwise, returns null
     */
    static Node get_named_attribute(Node node, String att_name) {
        if (node == null)
            return null;

        // Does the node have attributes?
        NamedNodeMap attributes = node.getAttributes();
        if (attributes != null) {
            // Does the node have this attribute?
            return attributes.getNamedItem(att_name);
        }

        // No attributes
        return null;
    }
}