Java tutorial
//package com.java2s; public class Main { /** * Takes an arbitrary string and encodes it in a way which allows its use as content of an XML element.<br/> * The string is left unchanged, if it does not violate any XML requirements. Otherwise it is encapsulated * in a CDATA element. * * @param data the string to escape, never null. * @return escaped version of the given string which is save for use as content of an XML element, never null. */ public static String escapeData(String data) { data = data.replace("&", "&"); data = data.replace("<", "<"); data = data.replace(">", ">"); return data; } }