public static String escapeXml(String buffer){
  int start=0;
  int length=buffer.length();
  char[] arrayBuffer=buffer.toCharArray();
  StringBuffer escapedBuffer=null;
  for (int i=0; i < length; i++) {
    char c=arrayBuffer[i];
    if (c <= HIGHEST_SPECIAL) {
      char[] escaped=specialCharactersRepresentation[c];
      if (escaped != null) {
        if (start == 0) {
          escapedBuffer=new StringBuffer(length + 5);
        }
        if (start < i) {
          escapedBuffer.append(arrayBuffer,start,i - start);
        }
        start=i + 1;
        escapedBuffer.append(escaped);
      }
    }
  }
  if (start == 0) {
    return buffer;
  }
  if (start < length) {
    escapedBuffer.append(arrayBuffer,start,length - start);
  }
  return escapedBuffer.toString();
}

public static String escapeXml ( String buffer ) { int start = 0 ; int length = buffer . length ( ) ; char [ ] arrayBuffer = buffer . toCharArray ( ) ; StringBuffer escapedBuffer = null ; for ( int i = 0 ; i < length ; i ++ ) { char c = arrayBuffer [ i ] ; if ( c <= HIGHEST_SPECIAL ) { char [ ] escaped = specialCharactersRepresentation [ c ] ; if ( escaped != null ) { if ( start == 0 ) { escapedBuffer = new StringBuffer ( length + 5 ) ; } if ( start < i ) { escapedBuffer . append ( arrayBuffer , start , i - start ) ; } start = i + 1 ; escapedBuffer . append ( escaped ) ; } } } if ( start == 0 ) { return buffer ; } if ( start < length ) { escapedBuffer . append ( arrayBuffer , start , length - start ) ; } return escapedBuffer . toString ( ) ; }
performs the following substring replacements ( to facilitate output to xml / html pages ) : & - > & amp ; < - > & lt ; > - > & gt ; " - > & # 034 ; ' - > & # 039 ; see also outsupport . writeescapedxml ( ) .
