Java tutorial
//package com.java2s; public class Main { public static String mailToXML(String sendTo, String subject, String content, String from) { StringBuffer sbRoot = new StringBuffer(); addReportRootHead(sbRoot); addReportRootNode(sbRoot, "msgtype", "email"); addReportRootNode(sbRoot, "sendTo", sendTo); addReportRootNode(sbRoot, "subject", subject); addReportRootNode(sbRoot, "content", content); addReportRootNode(sbRoot, "from", from); addReportRootTail(sbRoot); return sbRoot.toString(); } private static void addReportRootHead(StringBuffer sbRoot) { sbRoot.append("<?xml version='1.0' encoding='gb2312'?><root>"); } private static void addReportRootNode(StringBuffer sbRoot, String nodeName, String content) { sbRoot.append("<" + nodeName + ">" + content + "</" + nodeName + ">"); } private static void addReportRootTail(StringBuffer sbRoot) { sbRoot.append("</root>"); } }