Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

public class Main {
    public static String convert2XML(Map<String, String> params) {
        StringBuffer sb = new StringBuffer("<xml>");
        try {
            Iterator it = params.entrySet().iterator();
            while (it.hasNext()) {
                Entry entry = (Entry) it.next();
                sb.append("<" + entry.getKey() + ">");
                // sb.append("<![CDATA[" + entry.getValue() + "]]");
                sb.append(entry.getValue());
                sb.append("</" + entry.getKey() + ">");
            }
            sb.append("</xml>");

        } catch (Exception e) {
            e.printStackTrace();
        }
        return sb.toString();
    }
}