public String escape ( String in ) { StringBuffer out = new StringBuffer ( ) ; for ( char c : in . toCharArray ( ) ) { switch ( c ) { case ' ' : out . append ( "&lt;" ) ; break ; case ' ' : out . append ( "&gt;" ) ; break ; case ' ' : out . append ( "&amp;" ) ; break ; case ' ' : out . append ( "&quot;" ) ; break ; default : out . append ( c ) ; } } return out . toString ( ) ; }
Translate reserved XML characters to XML entities .