public static String encodeHtmlTag(String tag) { if (tag==null) return null; int length = tag.length(); StringBuffer encodedTag = new StringBuffer(2 * length); for (int i=0; i') encodedTag.append(">"); else if (c=='&') encodedTag.append("&"); else if (c=='"') encodedTag.append("""); //when trying to output text as tag's // value as in values="???". else if (c==' ') encodedTag.append(" "); else encodedTag.append(c); } return encodedTag.toString(); }