[plt-scheme] Escaping in X-expression attributes
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:
"collects/xml/private/writer.ss"
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
others.
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 ''' strings and replace them with single quotes.
for example:
(define remove-apos
(let ((re (regexp "'")))
(lambda (s)
(regexp-replace* re s "'"))))