Java XMLWriter 快速创建xml文件

阅读更多
package com.proxy.util;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: (le.qiao)
 * @e-mail: [email protected]
 * @myblog: http://qiaolevip.iteye.com
 * @date: 2012-8-17
 * 
 */
public class XmlWriter {

	public static void main(String[] args) {
		Map map = new HashMap();
		map.put("thirduserid", "24396353");
		map.put("thirdorderid", "2012050893537966006");

		Map map2 = new HashMap();
		map2.put("singleprice", "0.1");
		map2.put("quantity", "2");

		Map> map3 = new HashMap>();
		map3.put("orderinfo", map);
		map3.put("orderdeatil", map2);

		System.out.println(XmlWriter.write(map3));
	}

	public static String write(Map> map) {
		String reuslt = "";
		StringBuffer sb = new StringBuffer();
		sb.append("\n");
		if (map != null && map.size() > 0) {
			for (Map.Entry> map2 : map.entrySet()) {
				sb.append("<" + map2.getKey() + ">");
				sb.append("\n");
				for (Map.Entry map3 : map2.getValue().entrySet()) {
					sb.append("\t<" + map3.getKey() + ">" + map3.getValue() + "");
					sb.append("\n");
				}
				sb.append("");
				sb.append("\n");
			}
		}

		reuslt = sb.toString();

		return reuslt;
	}
}






	2
	0.1


	2012050893537966006
	24396353

你可能感兴趣的:(乔乐共享,java,xml,writer,file)