public static String encodeXML(String text){
  if (text == null) {
    return null;
  }
  final StringBuilder result=new StringBuilder();
  final StringCharacterIterator iterator=new StringCharacterIterator(text);
  char character=iterator.current();
  while (character != CharacterIterator.DONE) {
    if (character == '<') {
      result.append("&lt;");
    }
 else     if (character == '>') {
      result.append("&gt;");
    }
 else     if (character == '\"') {
      result.append("&quot;");
    }
 else     if (character == '\'') {
      result.append("&#039;");
    }
 else     if (character == '&') {
      result.append("&amp;");
    }
 else {
      result.append(character);
    }
    character=iterator.next();
  }
  return result.toString();
}

public static String encodeXML ( String text ) { if ( text == null ) { return null ; } final StringBuilder result = new StringBuilder ( ) ; final StringCharacterIterator iterator = new StringCharacterIterator ( text ) ; char character = iterator . current ( ) ; while ( character != CharacterIterator . DONE ) { if ( character == '<' ) { result . append ( "&lt;" ) ; } else if ( character == '>' ) { result . append ( "&gt;" ) ; } else if ( character == '\"' ) { result . append ( "&quot;" ) ; } else if ( character == '\'' ) { result . append ( "&#039;" ) ; } else if ( character == '&' ) { result . append ( "&amp;" ) ; } else { result . append ( character ) ; } character = iterator . next ( ) ; } return result . toString ( ) ; }
escape characters for text appearing as xml data , between tags . the following characters are replaced : < br > < < br > > < br > & < br > " < br > '
