void (final MultiText mtext, final int offset, final int len) { boolean needspace = false; boolean between = false; String ttext; for (int i = 0; i < len; i++) { final Content c = get(offset + i); switch (c.getCType()) { case Text: ttext = c.getValue(); if (Verifier.isAllXMLWhitespace(ttext)) { if (between && !ttext.isEmpty()) { needspace = true; } } else { if (between && (needspace || isSpaceFirst(ttext))) { mtext.appendText(Trim.NONE, " "); } mtext.appendText(Trim.COMPACT, ttext); between = true; needspace = isSpaceLast(ttext); } break; case CDATA: ttext = c.getValue(); if (Verifier.isAllXMLWhitespace(ttext)) { if (between && !ttext.isEmpty()) { needspace = true; } } else { if (between && (needspace || isSpaceFirst(ttext))) { mtext.appendText(Trim.NONE, " "); } mtext.appendCDATA(Trim.COMPACT, ttext); between = true; needspace = isSpaceLast(ttext); } break; case EntityRef: // treat like any other content. // raw. default: if (between && needspace) { mtext.appendText(Trim.NONE, " "); } mtext.appendRaw(c); between = true; needspace = false; break; } } }