Java tutorial
//package com.java2s; public class Main { public static String escapeXml(String payload) { StringBuilder out = new StringBuilder(); for (int i = 0; i < payload.length(); i++) { char c = payload.charAt(i); if ((c == 0x9) || (c == 0xA) || (c == 0xD) || ((c >= 0x20) && (c <= 0xD7FF)) || ((c >= 0xE000) && (c <= 0xFFFD)) || ((c >= 0x10000) && (c <= 0x10FFFF))) out.append(c); } return out.toString(); } }