public static String escapeXML ( String text ) { StringWriter writer = new StringWriter ( ) ; try { escapeXML ( text , writer ) ; } catch ( IOException e ) { // there is no reason for IO exception on a string writer throw new BugError ( "IO failure while attempting to write to string." ) ; } return writer . toString ( ) ; }
Escape text for reserved XML characters . Replace quotes apostrophe ampersand left and right angular brackets with entities . Return the newly created escaped string ; if text argument is null or empty returns an empty string .