Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
// modify it under the terms of the GNU General Public License

import java.util.HashMap;

import java.util.Map;

import org.w3c.dom.Attr;

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

public class Main {
    /** Return the attributes from the specified element as a Map */
    public static Map<String, String> getAttributesAsMap(Element e) {
        Map<String, String> result = new HashMap<String, String>();
        NamedNodeMap attrs = e.getAttributes();
        if (attrs != null) {
            int len = attrs.getLength();
            for (int i = 0; i < len; i++) {
                Node n = attrs.item(i);
                if (n instanceof Attr) {
                    Attr a = (Attr) n;
                    result.put(a.getName(), a.getValue());
                }
            }
        }
        return result;
    }
}