boolean lastIsWS = currentText == null || currentText.endsWith(" "); StringBuffer sb = new StringBuffer(); for( int i=start;i<start+length;i++) { if( Character.isWhitespace(ch[i]) ){ if( lastIsWS ) continue; sb.append(" "); lastIsWS = true; } else { sb.append(ch[i]); lastIsWS = false; } } String chars = sb.toString();  if( chars.trim().length() == 0 ) return; if( currentText != null ) currentText += chars; else { currentText = chars;  }
boolean lastIsWS = currentText == null || currentText.endsWith(" "); boolean hasNonWs = false; StringBuffer sb = new StringBuffer(); for (int i = start; i < start + length; i++) { if (Character.isWhitespace(ch[i])) { if (lastIsWS) continue; sb.append(" "); lastIsWS = true; } else { sb.append(ch[i]); lastIsWS = false; hasNonWs = true; } } String chars = sb.toString();              if (currentText != null) currentText += chars; else if (hasNonWs) { currentText = chars;  }
   public void characters (char ch[], int start, int length)   {      // The method trims whitespace from start and end of character data      boolean lastIsWS = currentText == null || currentText.endsWith(" ");      StringBuffer sb = new StringBuffer();      for( int i=start;i<start+length;i++) {        if( Character.isWhitespace(ch[i]) ){          if( lastIsWS )            continue;          sb.append(" ");          lastIsWS = true;        } else {          sb.append(ch[i]);          lastIsWS = false;        }      }      String chars = sb.toString(); //.trim();///        String chars = new String( ch, start, length ).trim();      if( chars.trim().length() == 0 )        return;      if( currentText != null )        currentText += chars;      else {        currentText = chars;///        //currentNode.addChild( currentText );      }   }