code: public String escapeString(String s)
      {
          if (s == null)
          {
              return null;
          }
          
          StringBuilder buffer = new StringBuilder();
          for(int i = 0; i < s.length(); i++)
          {
              buffer.append(escapeChar(s.charAt(i)));
          }
          return buffer.toString();
      }
docs: Replace any angle brackets, quotes, apostrophes or ampersands with the
  corresponding XML/HTML entities to avoid problems displaying the String in
  an XML document.  Assumes that the String does not already contain any
  entities (otherwise the ampersands will be escaped again).
  @param s The String to escape.
  @return The escaped String.