Java tutorial
//package com.java2s; //License from project: Apache License public class Main { private static final String[][] escapees = { { "&", "&" }, { "<", "<" }, { ">", ">" }, { "\"", """ } }; public static String xmlEscape(String str) { for (String[] escapee : escapees) { str = str.replaceAll(escapee[0], escapee[1]); } return str; } }