Java tutorial
//package com.java2s; public class Main { public static String xmlFilter(String input) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < input.length(); i++) { char c = input.charAt(i); if (c == '<') { sb.append("<"); } else if (c == '>') { sb.append(">"); } else if (c == '\'') { sb.append("'"); } else if (c == '"') { sb.append("""); } else if (c == '&') { sb.append("&"); } else { sb.append(c); } } return sb.toString(); } }