Java tutorial
//package com.java2s; //License from project: Open Source License public class Main { public static String escapeAttribute(String attribute) { return escapeAttribute(attribute, true); } public static String escapeAttribute(String attribute, boolean escapeEntities) { if (attribute == null) return ""; String ret = attribute; if (escapeEntities) ret = ret.replace("&", "&"); return ret.replace("\"", """).replace("'", "'"); } }