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 escape(String xmlstr) {
        StringBuffer buffer = new StringBuffer();
        for (int i = 0; i < xmlstr.length(); i++) {
            char c = xmlstr.charAt(i);
            if (c == '&')
                buffer.append("&amp;");
            else if (c == '<')
                buffer.append("&lt;");
            else if (c == '>')
                buffer.append("&gt;");
            else if (c == '"')
                buffer.append("&quot;");
            else if (c == '\'')
                buffer.append("&apos;");
            else
                buffer.append(c);
        }
        return buffer.toString();
    }
}