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 encodeXML(String xml) {

        if (xml == null)
            return "";

        char[] chars = xml.toString().toCharArray();

        StringBuffer out = new StringBuffer();

        for (char c : chars)
            switch (c) {
            case '&':
                out.append("&");

                break;

            case '<':
                out.append("&lt;");

                break;

            case '>':
                out.append("&gt;");

                break;

            case '\"':
                out.append("&quot;");

                break;

            default:
                out.append(c);
            }

        return out.toString();
    }
}