protected static String escapeXmlSpecialCharacters ( String aText ) { String result = aText ; result = result . replaceAll ( "&" , "&amp;" ) ; result = result . replaceAll ( "\'" , "\\\\&#039;" ) ; result = result . replaceAll ( "'" , "\\\\&#039;" ) ; return result ; }
Android specific escaping of characters . Note that since this is no real XML escaping the output string . xml file is potentially not valid XML . However this is explicitly allowed by Android .