class XMLUtil {

    /**
     * Escapes a string with the appropriated XML codes.
     *
     * @param s         the string to be escaped
     * @param onlyASCII codes above 127 will always be escaped with &amp;#nn; if <CODE>true</CODE>
     * @return the escaped string
     */
    public static String escapeXML(String s, boolean onlyASCII) {<FILL_FUNCTION_BODY>}
}

        char[] cc = s.toCharArray();
        int len = cc.length;
        StringBuilder sb = new StringBuilder();
        for (int c : cc) {
            switch (c) {
                case '<':
                    sb.append("&lt;");
                    break;
                case '>':
                    sb.append("&gt;");
                    break;
                case '&':
                    sb.append("&amp;");
                    break;
                case '"':
                    sb.append("&quot;");
                    break;
                case '\'':
                    sb.append("&apos;");
                    break;
                default:
                    if ((c == 0x9) || (c == 0xA) || (c == 0xD)
                            || ((c >= 0x20) && (c <= 0xD7FF))
                            || ((c >= 0xE000) && (c <= 0xFFFD))
                            || ((c >= 0x10000) && (c <= 0x10FFFF))) {
                        if (onlyASCII && c > 127) {
                            sb.append("&#").append(c).append(';');
                        } else {
                            sb.append((char) c);
                        }
                    }
            }
        }
        return sb.toString();
    
<no_super_class>