protected String escapeAttributeEntities(String text){
  char quote=format.getAttributeQuoteCharacter();
  char[] block=null;
  int i;
  int last=0;
  int size=text.length();
  for (i=0; i < size; i++) {
    String entity=null;
    char c=text.charAt(i);
switch (c) {
case '<':
      entity="&lt;";
    break;
case '>':
  entity="&gt;";
break;
case '\'':
if (quote == '\'') {
entity="&apos;";
}
break;
case '\"':
if (quote == '\"') {
entity="&quot;";
}
break;
case '&':
entity="&amp;";
break;
case '\t':
case '\n':
case '\r':
break;
default :
if ((c < 32) || shouldEncodeChar(c)) {
entity="&#" + (int)c + ";";
}
break;
}
if (entity != null) {
if (block == null) {
block=text.toCharArray();
}
buffer.append(block,last,i - last);
buffer.append(entity);
last=i + 1;
}
}
if (last == 0) {
return text;
}
if (last < size) {
if (block == null) {
block=text.toCharArray();
}
buffer.append(block,last,i - last);
}
String answer=buffer.toString();
buffer.setLength(0);
return answer;
}

protected String escapeAttributeEntities ( String text ) { char quote = format . getAttributeQuoteCharacter ( ) ; char [ ] block = null ; int i ; int last = 0 ; int size = text . length ( ) ; for ( i = 0 ; i < size ; i ++ ) { String entity = null ; char c = text . charAt ( i ) ; switch ( c ) { case '<' : entity = "&lt;" ; break ; case '>' : entity = "&gt;" ; break ; case '\'' : if ( quote == '\'' ) { entity = "&apos;" ; } break ; case '\"' : if ( quote == '\"' ) { entity = "&quot;" ; } break ; case '&' : entity = "&amp;" ; break ; case '\t' : case '\n' : case '\r' : break ; default : if ( ( c < 32 ) || shouldEncodeChar ( c ) ) { entity = "&#" + ( int ) c + ";" ; } break ; } if ( entity != null ) { if ( block == null ) { block = text . toCharArray ( ) ; } buffer . append ( block , last , i - last ) ; buffer . append ( entity ) ; last = i + 1 ; } } if ( last == 0 ) { return text ; } if ( last < size ) { if ( block == null ) { block = text . toCharArray ( ) ; } buffer . append ( block , last , i - last ) ; } String answer = buffer . toString ( ) ; buffer . setLength ( 0 ) ; return answer ; }
this will take the pre - defined entities in xml 1 . 0 and convert their character representation to the appropriate entity reference , suitable for xml attributes .
