Java tutorial
//package com.java2s; public class Main { /** * Escape XML * @param str The string * @return The string as valid XML */ public static String escapeXML(String str) { return str.replaceAll("\"", """).replaceAll("&", "&").replaceAll("<", "<") .replaceAll(">", ">").replaceAll("'", "'"); } }