[plt-scheme] Escaping in X-expression attributes

From: jason songhurst (songhurst at yahoo.com)
Date: Fri Aug 9 13:44:23 EDT 2002

Jens Axel Søgaard wrote:
 > I have a hard time figuring out how to get the web-server
 > to produce a " or a ' in the output when feeded an X-expression.
 > I simply can't figure out how to escape properly in the attributes
 > of X-expressions.

the code that escapes characters (converts ' into ') in attributes 
(and in xml text, but that isn't really your concern) is in the file:

see specifically the definition of (write-xml-element ...), which calls 
(escape s alist). the (escape ...) function is where the work is done.

in summary:
   as currenly (v201) written, there is no escape from the escape.  :)

but there are workarounds...  here are some that i found.  you may find 

workaround 1:
   remove the ''' escape from the escape-attribute-table
   (line 153 in writer.ss)

   it is not needed if the string is quoted with double quotes.
   the only chars that need to be escaped in double-quoted attribute
   values are &, <, and ".

workaround 2: (if you can't change the library)
   un-escape manually.

   find the '&apos;' strings and replace them with single quotes.

   for example:
   (define remove-apos
     (let ((re (regexp "&apos;")))
       (lambda (s)
         (regexp-replace* re s "'"))))

Posted on the users mailing list.