Here you can find the source of SanitizeXmlString(String xml)
public static String SanitizeXmlString(String xml)
//package com.java2s; public class Main { public static String SanitizeXmlString(String xml) { if (xml == null || xml.isEmpty()) { return xml; }/* ww w.j a va 2s . com*/ StringBuilder buffer = new StringBuilder(xml.length()); for (int i = 0; i < xml.length(); i++) { if (IsLegalXmlChar(xml.charAt(i))) { buffer.append(xml.charAt(i)); } } return buffer.toString(); } public static boolean IsLegalXmlChar(int character) { return (character == 0x9 /* == '\t' == 9 */ || character == 0xA /* == '\n' == 10 */ || character == 0xD /* == '\r' == 13 */ || (character >= 0x20 && character <= 0xD7FF) || (character >= 0xE000 && character <= 0xFFFD) || (character >= 0x10000 && character <= 0x10FFFF)); } }