Java tutorial
//package com.java2s; /******************************************************************************* * Copyright (c) 2002-2005 IBM Corporation and others. * 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: * IBM - Initial API and implementation *******************************************************************************/ public class Main { /** * XML encode a text string. * * @param text - a String. * @return an XML encoded text string. */ public static String xmlRemoveEscapedString(String text) { if (text == null) return text; else { StringBuffer sb = new StringBuffer(text); int i = sb.indexOf("
"); while (i != -1) { sb.replace(i, i + 5, "\r"); i = sb.indexOf("
"); } i = sb.indexOf("<"); while (i != -1) { sb.replace(i, i + 4, "<"); i = sb.indexOf("<"); } i = sb.indexOf(">"); while (i != -1) { sb.replace(i, i + 4, ">"); i = sb.indexOf(">"); } i = sb.indexOf("""); while (i != -1) { sb.replace(i, i + 6, "\""); i = sb.indexOf("""); } i = sb.indexOf("'"); while (i != -1) { sb.replace(i, i + 6, "\'"); i = sb.indexOf("'"); } i = sb.indexOf("&"); while (i != -1) { sb.replace(i, i + 5, "&"); i = sb.indexOf("&"); } return sb.toString(); } } }