Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    /**
     * <p>
     * Escapes XML reserved characters to their corresponding XML-safe versions.
     * Specifically, this method:
     * </p>
     * <xmp> Replaces & with &amp; Replaces < with &lt; Replaces > with &gt;
     * </xmp>
     * 
     * @param txt
     *            Source string with text that needs to have XML characters
     *            escaped
     * @return String that has reserved XML characters escaped
     */
    public static String escapeXMLText(String txt) {
        return txt.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;");
    }
}