code: public static String escapeXML(final char[] chars, final int offset, final int length) {
          final StringBuilder escaped = new StringBuilder();
  
          final int end = offset + length;
          for (int i = offset; i < end; ++i) {
              final char c = chars[i];
  
              switch (c) {
              case '\'':
                  escaped.append("&apos;");
                  break;
              case '\"':
                  escaped.append("&quot;");
                  break;
              case '<':
                  escaped.append("&lt;");
                  break;
              case '>':
                  escaped.append("&gt;");
                  break;
              case '&':
                  escaped.append("&amp;");
                  break;
              default:
                  escaped.append(c);
              }
          }
  
          return escaped.toString();
      }
docs: Escape XML characters.
  
  @param chars char arrays
  @param offset start position
  @param length arrays lenth
  @return escaped value