Here you can find the source of toXMLString(String org)
public static String toXMLString(String org)
//package com.java2s; //License from project: Open Source License public class Main { public static String toXMLString(String org) { if (org == null) return ""; StringBuffer result = new StringBuffer(org.length()); char[] chars = org.toCharArray(); for (int i = 0; i < chars.length; i++) { if (chars[i] == '<') result.append("<"); else if (chars[i] == '>') result.append(">"); else if (chars[i] == '&') result.append("&"); else if (chars[i] == '\r') result.append(" "); else if (chars[i] == '\n') result.append(" "); else if (chars[i] == '\"') result.append("""); else//www . j av a 2s . c o m result.append(chars[i]); } return result.toString(); } }