Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import org.w3c.dom.Attr;

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

public class Main {
    public static void copyAttributes(Node from, Node to) {
        NamedNodeMap map = from.getAttributes();
        for (int i = 0; i < map.getLength(); i++) {
            Node attr = map.item(i);
            addAttribute(to, attr.getNodeName(), attr.getNodeValue());
        }
    }

    public static Attr addAttribute(Node parent, String name, String value) {
        Attr node = parent.getOwnerDocument().createAttribute(name);
        node.setValue(value);
        parent.getAttributes().setNamedItem(node);
        return node;
    }
}