Java tutorial
//package com.java2s; public class Main { /** * Escape all characters that would result in invalid XML when exporting the * input as an attribute value in an XML tag. * * @param input Text to escape * @return Safe text to include within XML attributes */ public static String ensureSafeXML(String input) { if (input == null) return ""; String output = input.replaceAll("&", "&"); output = output.replaceAll("&", "&"); output = output.replaceAll("<", "<"); output = output.replaceAll(">", "&rt;"); output = output.replaceAll("\"", """); return output; } }