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 {
    /**
     * Get the attribute value from specified node.
     * 
     * @param node
     *          the node
     * @param attributeName
     *          the attribute name
     * @return the attribut value
     */
    public static String getNodeAttribute(Node node, String attributeName) {
        if (null == node) {
            return null;
        }
        NamedNodeMap attributes = node.getAttributes();
        if (null == attributes) {
            return null;
        }
        Node n = attributes.getNamedItem(attributeName);
        if (null == n) {
            return null;
        }
        return n.getNodeValue();
    }

    /**
     * Get the value of specified node.
     * 
     * @param node
     *          the node
     * @return the value of the node
     */
    public static String getNodeValue(Node node) {
        if (null == node) {
            return null;
        }
        if (null == node.getFirstChild()) {
            return null;
        }
        return node.getFirstChild().getNodeValue();
    }
}