Here you can find the source of toXMLString(String string)
public static final String toXMLString(String string)
//package com.java2s; /******************************************************************************* * Copyright (c) 2011, 2012 Red Hat, Inc. * All rights reserved. //from www .j a v a 2 s . c o m * This program is 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: * Red Hat, Inc. - initial API and implementation *******************************************************************************/ public class Main { public static final String toXMLString(String string) { if (string == null || string.isEmpty()) return ""; //$NON-NLS-1$ StringBuffer xmlString = new StringBuffer(); int stringLength = string.length(); for (int i = 0; i < stringLength; i++) { char c = string.charAt(i); if (c == '"') xmlString.append("""); //$NON-NLS-1$ else if (c == '&') xmlString.append("&"); //$NON-NLS-1$ else if (c == '\'') xmlString.append("'"); //$NON-NLS-1$ else if (c == '<') xmlString.append("<"); //$NON-NLS-1$ else if (c == '>') xmlString.append(">"); //$NON-NLS-1$ else xmlString.append(c); } return xmlString.toString(); } }