Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2004, 2007 Boeing.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Boeing - initial API and implementation
 *******************************************************************************/

public class Main {
    /**
     * Given text strings containing xml reserved characters, replace with valid xml representation characters > => & gt;
     * < => & lt; & => & amp; ' => & apos; " => & quot;
     *
     * @param text text to be converted to valid XML representation characters
     */
    public static String textToXml(String text) {
        if (text == null || text.equals("")) {
            return "";
        }
        String str = text;
        str = str.replaceAll("&", "&amp;");
        str = str.replaceAll(">", "&gt;");
        str = str.replaceAll("<", "&lt;");
        str = str.replaceAll("'", "&apos;");
        str = str.replaceAll("\"", "&quot;");
        return str;
    }
}