Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    /**
     * Takes an arbitrary string and encodes it in a way which allows its use as content of an XML element.<br/>
     * The string is left unchanged, if it does not violate any XML requirements. Otherwise it is encapsulated
     * in a CDATA element. 
     * 
     * @param data the string to escape, never null. 
     * @return escaped version of the given string which is save for use as content of an XML element, never null.
     */
    public static String escapeData(String data) {
        data = data.replace("&", "&amp;");
        data = data.replace("<", "&lt;");
        data = data.replace(">", "&gt;");

        return data;
    }
}