Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    public static String msgToXML(String phoneNumber, String smsContent, String from) {
        StringBuffer sbRoot = new StringBuffer();
        addReportRootHead(sbRoot);
        addReportRootNode(sbRoot, "msgtype", "sms");
        addReportRootNode(sbRoot, "from", from);
        addReportRootNode(sbRoot, "phoneNumber", phoneNumber);
        addReportRootNode(sbRoot, "content", smsContent);
        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>");
    }
}