Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
// License as published by the Free Software Foundation; either

import java.util.Map;

import org.w3c.dom.Element;

public class Main {
    /**
     * Sets the Map as DOM attributes on the given Element.
     * <p>
     * This implementation uses <code>element.setAttribute</code>. Therefore if the element already
     * has attributes, the new attributes are added amongst them. If attributes with the same name
     * already exist, they are overwritten.
     */

    public static void setMapAsAttributes(Element element, Map<String, String> attributes) {

        if (attributes == null) {
            return;
        }

        for (Map.Entry<String, String> entry : attributes.entrySet()) {

            String value = entry.getValue();

            if (value == null) {
                element.removeAttribute(entry.getKey());
                continue;
            }

            element.setAttribute(entry.getKey(), value);
        }
    }
}