result.replace(i + delta, i + delta + 1, replacement);
String temp = result.toString(); String firstHalf = temp.substring(0, i + delta); String secondHalf = temp.substring(i + delta + 1, temp.length()); result = new StringBuffer(firstHalf + replacement + secondHalf);
    protected static String quoteXMLChars(String s) {        StringBuffer result = null;        for(int i = 0, max = s.length(), delta = 0; i < max; i++) {            char c = s.charAt(i);            String replacement = null;                        if (c == '&') {                replacement = "&amp;";            } else if (c == '<') {                replacement = "&lt;";            } else if (c == '\r') {                replacement = "&#13;";            } else if (c == '>') {                replacement = "&gt;";            } else if (c == '"') {                replacement = "&quot;";            } else if (c == '\'') {                replacement = "&apos;";            }                        if (replacement != null) {                if (result == null) {                    result = new StringBuffer(s);                }                result.replace(i + delta, i + delta + 1, replacement);                delta += (replacement.length() - 1);            }        }        if (result == null) {            return s;        }        return result.toString();    }