StringBuffer sb = new StringBuffer(); for(int i=startpos;i<startpos+length;i++) { switch( ch[i] ) { case '<': sb.append("&lt;"); break; case '>': sb.append(">"); break; case '\'': sb.append("&apos;"); break; case '&': sb.append("&amp;"); break; case '"': sb.append("&quot;"); break; default: sb.append(ch[i]); } } String chars = sb.toString();  if( chars.length() == 0 ) return;/*
if( length == 0 ) return; String chars = toEntities(ch, startpos, length); /*
   public void characters (char ch[], int startpos, int length)   {     state = STATE_CHARS;      if(childcounter!=HAS_CONTENT)         printWithNL(">",prettyPrint);      childcounter = HAS_CONTENT;      StringBuffer sb = new StringBuffer();      for(int i=startpos;i<startpos+length;i++) {        switch( ch[i] ) {          case '<': sb.append("&lt;");                break;          case '>': sb.append(">");                break;          case '\'': sb.append("&apos;");                break;          case '&': sb.append("&amp;");                break;          case '"': sb.append("&quot;");                break;          default:              sb.append(ch[i]);        }      }      String chars = sb.toString();//        String chars = new String( ch, startpos, length ).trim();      if( chars.length() == 0 )        return;/*      int start=0,next=-1;      do {        next=chars.indexOf("\n",start);        if( next==-1)          pw.println(chars.substring(start));        else {          pw.println(chars.substring(start,next));          start=next+1;        }      } while( next != -1 );*/      printWithNL(chars,prettyPrint);      //System.err.println("OUT:"+chars);   }