Here you can find the source of xmlEncode(String s)
public static String xmlEncode(String s)
//package com.java2s; //it under the terms of the GNU Affero General Public License as published by public class Main { public static String xmlEncode(String s) { if (s == null) return null; StringBuilder sb = new StringBuilder(s.length() + 16); for (int i = 0, n = s.length(); i < n; i++) { char c = s.charAt(i); switch (c) { case '&': sb.append("&"); break; case '<': sb.append("<"); break; case '\'': sb.append("'"); break; case '\"': sb.append("""); break; default: if (c >= 128) sb.append(String.format("&#x%04x;", (int) c)); else sb.append(c);//from w ww. j a v a 2s . co m break; } } return sb.toString(); } }