Encode string to prevent causing errors in XML using URL encoding - Android java.net

Android examples for java.net:URL

Description

Encode string to prevent causing errors in XML using URL encoding

Demo Code

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;

public class Main{

    /**//w w  w .j  a  va 2 s .  com
     * .
     */
    public static String escapeXml(String s) {
        String result = "";

        try {
            result = URLEncoder.encode(s, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return result;
    }

}

Related Tutorials