Escape XML String

Escape the XML value in a String.

Javadoc available at https://www.javatapas.com/docs/javatapas/string/EscapeXmlString.html


public static String escapeXmlString(String str){

	// this must be done first or else the escapes below are over-written.
	str = str.replaceAll("&","&");

	str = str.replaceAll("<","&lt;");
	str = str.replaceAll(">","&gt;");
	str = str.replaceAll("\"\"","&quot;");
	str = str.replaceAll("\"","&quot;");
	str = str.replaceAll("'","&apos;");

	str = str.replaceAll("“","&quot;");
	str = str.replaceAll("’","&apos;");
	str = str.replaceAll("–","-");

	return str;

}