public static String xmlAttribEncode ( final String attrValue ) { final StringBuffer buf = new StringBuffer ( attrValue ) ; int quotePos ; for ( quotePos = - 1 ; ( quotePos = buf . indexOf ( "\"" , quotePos + 1 ) ) >= 0 ; ) { buf . deleteCharAt ( quotePos ) ; buf . insert ( quotePos , "&quot;" ) ; quotePos += 5 ; } for ( quotePos = - 1 ; ( quotePos = buf . indexOf ( "<" , quotePos + 1 ) ) >= 0 ; ) { buf . deleteCharAt ( quotePos ) ; buf . insert ( quotePos , "&lt;" ) ; quotePos += 3 ; } for ( quotePos = - 1 ; ( quotePos = buf . indexOf ( ">" , quotePos + 1 ) ) >= 0 ; ) { buf . deleteCharAt ( quotePos ) ; buf . insert ( quotePos , "&gt;" ) ; quotePos += 3 ; } return buf . toString ( ) ; }
Replaces any embedded quotes in the string so that the value can be placed in an attribute in an XML file