Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    /**
     * XML attribute value Encode
     * @param s xml attribute values
     * @return convert "&"->"&amp;", "<"->"&lt;", ">"->"&gt;" 
     */
    public static String encodeXMLReservedWords(String s) {
        if (s.contains("&")) {
            s = s.replaceAll("&", "&amp;");
        }

        if (s.contains("<")) {
            s = s.replaceAll("<", "&lt;");
        }

        if (s.contains(">")) {
            s = s.replaceAll(">", "&gt;");
        }
        return s;
    }
}