Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

public class Main {
    /**
     *  Gets a named attribute of a Node<p>
     *  @param node The node to search
     *  @param attr The name of the attribute to get
     */
    public synchronized static String getAttribute(Node node, String attr) {
        if (node == null)
            throw new IllegalArgumentException("Node argument cannot be null");
        if (attr == null)
            throw new IllegalArgumentException("Node attribute argument cannot be null");

        NamedNodeMap map = node.getAttributes();
        if (map != null) {
            Node an = map.getNamedItem(attr);
            if (an != null)
                return an.getNodeValue();
        }

        return null;
    }
}