Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.PrintWriter;

public class Main {
    public static void writeXML(PrintWriter out, String str) {
        for (int i = 0; i < str.length(); i++) {
            char ch = str.charAt(i);

            switch (ch) {
            case '<':
                out.write("&lt;");
                break;

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

            case '&':
                out.write("&amp;");
                break;

            case '"':
                out.write("&quot;");
                break;

            case '\'':
                out.write("&apos;");
                break;

            case '\r':
            case '\n':
                out.write(ch);
                break;

            default:
                if ((ch < 32) || (ch > 126)) {
                    out.write("&#x");
                    out.write(Integer.toString(ch, 16));
                    out.write(';');
                } else {
                    out.write(ch);
                }
                break;
            }
        }
    }
}