Here you can find the source of encodeXMLString(String aString, PrintWriter aWriter)
public static final void encodeXMLString(String aString, PrintWriter aWriter)
//package com.java2s; //License from project: Open Source License import java.io.PrintWriter; public class Main { public static final void encodeXMLString(String aString, PrintWriter aWriter) { int len = aString.length(); for (int i = 0; i < len; i++) { char ch = aString.charAt(i); switch (ch) { case '&': aWriter.print("&"); break; case '>': aWriter.print(">"); break; case '<': aWriter.print("<"); break; case '\'': aWriter.print("'"); break; case '"': aWriter.print("""); break; default: if (ch < ' ' || ch > '~') { aWriter.print("&#"); aWriter.print((int) ch); aWriter.print(';'); } else { aWriter.print(ch);//from w ww . ja va2 s .c o m } } } } }