Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    /**
     * Escape all characters that would result in invalid XML when exporting the 
     * input as an attribute value in an XML tag.
     * 
     * @param input Text to escape
     * @return Safe text to include within XML attributes
     */
    public static String ensureSafeXML(String input) {
        if (input == null)
            return "";

        String output = input.replaceAll("&", "&");
        output = output.replaceAll("&", "&");
        output = output.replaceAll("<", "&lt;");
        output = output.replaceAll(">", "&rt;");

        output = output.replaceAll("\"", "&quot;");

        return output;
    }
}