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 double value of the named attribute for the given node
     * If no such attribute exists, returns 0.0
     */
    public static double getDblValue(Node node, String name) {
        // Look for the attribute
        Node att = get_named_attribute(node, name);
        if (att != null) {
            // Return the value
            return Double.valueOf(att.getNodeValue()).doubleValue();
        } else {
            // No such attribute
            return 0.0;
        }
    }

    /**
     * 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;
    }
}