public static final String convertToText(final String input,final boolean isXMLExtraction){
  final StringBuffer output_data;
  if (isXMLExtraction) {
    final byte[] rawData=StringUtils.toBytes(input);
    final int length=rawData.length;
    int ptr=0;
    boolean inToken=false;
    for (int i=0; i < length; i++) {
      if (rawData[i] == '<') {
        inToken=true;
        if (rawData[i + 1] == 'S' && rawData[i + 2] == 'p' && rawData[i + 3] == 'a' && rawData[i + 4] == 'c' && rawData[i + 5] == 'e') {
          rawData[ptr]='\t';
          ptr++;
        }
      }
 else       if (rawData[i] == '>') {
        inToken=false;
      }
 else       if (!inToken) {
        rawData[ptr]=rawData[i];
        ptr++;
      }
    }
    final byte[] cleanedString=new byte[ptr];
    System.arraycopy(rawData,0,cleanedString,0,ptr);
    output_data=new StringBuffer(new String(cleanedString));
  }
 else {
    output_data=new StringBuffer(input);
  }
  return output_data.toString();
}

public static final String convertToText ( final String input , final boolean isXMLExtraction ) { final StringBuffer output_data ; if ( isXMLExtraction ) { final byte [ ] rawData = StringUtils . toBytes ( input ) ; final int length = rawData . length ; int ptr = 0 ; boolean inToken = false ; for ( int i = 0 ; i < length ; i ++ ) { if ( rawData [ i ] == '<' ) { inToken = true ; if ( rawData [ i + 1 ] == 'S' && rawData [ i + 2 ] == 'p' && rawData [ i + 3 ] == 'a' && rawData [ i + 4 ] == 'c' && rawData [ i + 5 ] == 'e' ) { rawData [ ptr ] = '\t' ; ptr ++ ; } } else if ( rawData [ i ] == '>' ) { inToken = false ; } else if ( ! inToken ) { rawData [ ptr ] = rawData [ i ] ; ptr ++ ; } } final byte [ ] cleanedString = new byte [ ptr ] ; System . arraycopy ( rawData , 0 , cleanedString , 0 , ptr ) ; output_data = new StringBuffer ( new String ( cleanedString ) ) ; } else { output_data = new StringBuffer ( input ) ; } return output_data . toString ( ) ; }
strip out xml tags and put in a tab ( do not use on chinese text )
