Android examples for XML:XML String
encode XML String
//package com.java2s; public class Main { public static void main(String[] argv) throws Exception { String s = "java2s.com"; System.out.println(encode(s)); }/*from w w w. ja v a 2s. co m*/ public static String encode(String s) { String retStr = s; if (s.indexOf("<") >= 0) retStr = s.replaceAll("<", "<"); else if (s.indexOf(">") >= 0) retStr = s.replaceAll(">", ">"); else if (s.indexOf("&") >= 0) retStr = s.replaceAll("&", "&"); else if (s.indexOf("\"") >= 0) retStr = s.replaceAll("\"", """); else if (s.indexOf("'") >= 0) retStr = s.replaceAll("\'", "'"); return retStr; } }