Html-encode the string.
StringBuilder sb = new StringBuilder();
char c;
for (int i = 0; i < s.length(); i++) {
c = s.charAt(i);
switch (c) {
case '<":
sb.append("<"); //$NON-NLS-1$
break;
case '>":
sb.append(">"); //$NON-NLS-1$
break;
case '&":
sb.append("&"); //$NON-NLS-1$
break;
case '\'":
//http://www.w3.org/TR/xhtml1
// The named character reference ' (the apostrophe, U+0027) was introduced in
// XML 1.0 but does not appear in HTML. Authors should therefore use ' instead
// of ' to work as expected in HTML 4 user agents.
sb.append("'"); //$NON-NLS-1$
break;
case '"":
sb.append("""); //$NON-NLS-1$
break;
default:
sb.append(c);
}
}
return sb.toString();