code: private String escapeStringSpecialCharacters(String str)
      {
          if (logger.isLoggable(Level.FINER)) logger.exiting(className, "escapeStringSpecialCharacters(String)");
  
          if (str != null)
          {
              StringBuffer strBuf = new StringBuffer("");
  
              for (int i = 0; i < str.length(); i++)
              {
                  char strChar = str.charAt(i);
  
                  switch (strChar)
                  {
                      case '"':
                          {
                              strBuf.append("\\\"");
                              break;
                          }
                      case '\t':
                          {
                              strBuf.append("\\t");
                              break;
                          }
                      case '\b':
                          {
                              strBuf.append("\\b");
                              break;
                          }
                      case '\\':
                          {
                              strBuf.append("\\\\");
                              break;
                          }
                      case '\f':
                          {
                              strBuf.append("\\f");
                              break;
                          }
                      case '\r':
                          {
                              strBuf.append("\\r");
                              break;
                          }
                      case '/':
                          {
                              strBuf.append("\\/");
                              break;
                          }
                      default:
                          {
                              if ((strChar >= 32) && (strChar <= 126) )
                              {
                                  strBuf.append(strChar);
                              }
                              else if (strChar > 126)
                              {
                                if ((escapeNonAsciiChars)) 
                                {
                                    strBuf.append("\\u");
                                    StringBuffer sb = new StringBuffer(Integer.toHexString(strChar));
                                    while (sb.length() < 4)
                                    {
                                        sb.insert(0,'0');
                                    }
                                    strBuf.append(sb.toString());
                                }
                                else {
                                  strBuf.append(strChar);
                                }
                              }
                              else 
                              {
                                  strBuf.append("\\u");
                                  StringBuffer sb = new StringBuffer(Integer.toHexString(strChar));
                                  while (sb.length() < 4)
                                  {
                                      sb.insert(0,'0');
                                  }
                                  strBuf.append(sb.toString());
                              }
  
                              break;
                          }
                  }
              }
              str = strBuf.toString();
          }
          if (logger.isLoggable(Level.FINER)) logger.exiting(className, "escapeStringSpecialCharacters(String)");
          return str;
      }
docs: Internal method to escape special attribute name characters, to handle things like name spaces.
  @param str The string to escape the characters in.