public static String doEntityReference (String text) {
        StringBuffer result = new StringBuffer();
        for (int i = 0; i < text.length(); i++) {
            char ch = text.charAt(i);
            if (ch == '<')
                result.append("&lt;");
            else if (ch == '&')
                result.append("&amp;");
            else if (ch == '>')
                result.append("&gt;");
            else
                result.append(ch);
        }
        return result.toString();
    }