code: public static void escapeXML(StringBuilder sb) {
          // double quote -- quot
          // ampersand -- amp
          // less than -- lt
          // greater than -- gt
          // apostrophe -- apos
          for (int i = 0; i < sb.length();) {
              int codePoint = Character.codePointAt(sb, i);
              int length = Character.charCount(codePoint);
              if (codePoint == '<') {
                  sb.replace(i, i + length, LT);
                  i += LT.length();
              } else if (codePoint == '>') {
                  sb.replace(i, i + length, GT);
                  i += GT.length();
              } else if (codePoint == '\"') {
                  sb.replace(i, i + length, QUOT);
                  i += QUOT.length();
              } else if (codePoint == '&') {
                  sb.replace(i, i + length, AMP);
                  i += AMP.length();
              } else if (codePoint == '\'') {
                  sb.replace(i, i + length, APOS);
                  i += APOS.length();
              } else {
                  i += length;
              }
          }
      }
docs: Escapes a string builder so that it is valid XML.
  
  @param sb
  The string builder to escape.