Here you can find the source of textToXml(String text)
Parameter | Description |
---|---|
text | text to be converted to valid XML representation characters |
public static String textToXml(String text)
//package com.java2s; /******************************************************************************* * Copyright (c) 2004, 2007 Boeing./*w ww .jav a2s.c o m*/ * 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("&", "&"); str = str.replaceAll(">", ">"); str = str.replaceAll("<", "<"); str = str.replaceAll("'", "'"); str = str.replaceAll("\"", """); return str; } }