Here you can find the source of xmlEncode(String string)
public static final String xmlEncode(String string)
//package com.java2s; /******************************************************************************* * Copyright (c) 2005, 2007 Remy Suen//from w ww . j ava 2s. c om * 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: * Remy Suen <remy.suen@gmail.com> - initial API and implementation ******************************************************************************/ public class Main { public static final String xmlEncode(String string) { if (string.equals("")) { //$NON-NLS-1$ return string; } int index = string.indexOf('&'); while (index != -1) { string = string.substring(0, index) + "&" //$NON-NLS-1$ + string.substring(index + 1); index = string.indexOf('&', index + 1); } index = string.indexOf('"'); while (index != -1) { string = string.substring(0, index) + """ //$NON-NLS-1$ + string.substring(index + 1); index = string.indexOf('"', index + 1); } index = string.indexOf('\''); while (index != -1) { string = string.substring(0, index) + "'" //$NON-NLS-1$ + string.substring(index + 1); index = string.indexOf('\'', index + 1); } index = string.indexOf('<'); while (index != -1) { string = string.substring(0, index) + "<" //$NON-NLS-1$ + string.substring(index + 1); index = string.indexOf('<', index + 1); } index = string.indexOf('>'); while (index != -1) { string = string.substring(0, index) + ">" //$NON-NLS-1$ + string.substring(index + 1); index = string.indexOf('>', index + 1); } return string; } }