code: public static String escapeXmlString(String str, boolean escapeQuots)
      {
          if (str == null) {
              return "";
          }
          StringBuffer buf = new StringBuffer();
          char[] array = str.toCharArray();
          for (int i = 0; i < array.length; i++) {
              if (array[i] == '>'
                  || array[i] == '&'
                  || array[i] == '<'
                  || (escapeQuots && (array[i] == '\'' || array[i] == '"')))
              {
                  buf.append("&#x" + Integer.toHexString(array[i]) + ";");
              } else {
                  buf.append(array[i]);
              }
          }
          return buf.toString();
      }
docs: Returns the escaped string.
  
  @param str the string to escape
  @param escapeQuots if this flag is <code>true</code> then "'" and "\""
  symbols also will be escaped
  @return the escaped string.