Java tutorial
//package com.java2s; public class Main { public static String xmlSpecialChar(String value) { StringBuilder sb = new StringBuilder(value.length()); char[] chars = value.toCharArray(); for (char c : chars) { switch (c) { case '<': sb.append("<"); break; case '>': sb.append(">"); break; case '&': sb.append("&"); break; case '\'': sb.append("'"); break; case '"': sb.append("""); break; default: sb.append(c); break; } } return sb.toString(); } }