Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

import java.util.*;

public class Main {
    private static final String TAG_ATTR = "attr";

    public static void saveAttributesToNode(Node node, Properties props) {
        Document doc = node.getOwnerDocument();
        Element elem;
        Enumeration keys = props.keys();
        Enumeration elems = props.elements();
        while (keys.hasMoreElements()) {
            String s;
            s = keys.nextElement().toString() + "=" + elems.nextElement().toString();
            addTextTag(node, TAG_ATTR, s);
        }

    }

    public static void addTextTag(Node node, String tagName, String text) {
        Document doc = node.getOwnerDocument();
        Element elem = doc.createElement(tagName);
        elem.appendChild(doc.createTextNode(text));
        node.appendChild(elem);
    }
}