Java tutorial
//package com.java2s; public class Main { public static String getAsAttribute(String attrName, String value) { if (value != null) { String val = value.replace("&", "&"); //val = val.replace("\"", """); val = val.replace("\"", "'"); val = val.replace("<", "<").replace(">", ">"); return " " + attrName + "=\"" + val + "\" "; } else { return " " + attrName + "=\"\" "; } } }