code: private static String _escapeXML(String value) {
          int len = value.length();
          if (0 == len) {
              return value;
          }
          StringBuilder buf = null;
          for (int i = 0; i < len; i++) {
              char ch = value.charAt(i);
              switch (ch) {
                  case '<':
                      if (buf == null) {
                          buf = new StringBuilder(len * 2);
                          if (i > 0) {
                              buf.append(value.substring(0, i));
                          }
                      }
                      buf.append("&lt;");
                      break;
                  case '>':
                      if (buf == null) {
                          buf = new StringBuilder(len * 2);
                          if (i > 0) {
                              buf.append(value.substring(0, i));
                          }
                      }
                      buf.append("&gt;");
                      break;
                  case '\"':
                      if (buf == null) {
                          buf = new StringBuilder(len * 2);
                          if (i > 0) {
                              buf.append(value.substring(0, i));
                          }
                      }
                      buf.append("&quot;");
                      break;
                  case '\'':
                      if (buf == null) {
                          buf = new StringBuilder(len * 2);
                          if (i > 0) {
                              buf.append(value.substring(0, i));
                          }
                      }
                      buf.append("&apos;");
                      break;
                  case '&':
                      if (buf == null) {
                          buf = new StringBuilder(len * 2);
                          if (i > 0) {
                              buf.append(value.substring(0, i));
                          }
                      }
                      buf.append("&amp;");
                      break;
                  default:
                      if (buf != null) {
                          buf.append(ch);
                      }
                      break;
              }
          }
          if (buf != null) {
              return buf.toString();
          }
          return value;
      }
docs: we use this method to replace apache StringEscapeUtils, which is slower