public static String encode(String xmlToEncode){
        StringBuilder encodedXml = new StringBuilder();
        int charCode;

        for(Character c : xmlToEncode.toCharArray()){
            charCode = (int) c;

            switch (charCode){
                case 34:
                    encodedXml.append("&quot;");
                    break;
                case 38:
                    encodedXml.append("&amp;");
                    break;
                case 39:
                    encodedXml.append("&apos;");
                    break;
                case 60:
                    encodedXml.append("&lt;");
                    break;
                case 62:
                    encodedXml.append("&gt;");
                    break;
                default:
                    encodedXml.append(c);
                    break;
            }
        }

        return encodedXml.toString();
    }