[racket] cdata section is not normalized by read-xml

From: Jay McCarthy (jay.mccarthy at gmail.com)
Date: Wed Nov 10 07:39:51 EST 2010

I think a better thing to do is for users who want it to make

make-cdata* and cdata-string*

which add the wrappers themselves.

The places you're referring to in the code abuse this property of
cdata to generate unquoted XML strings. This is very useful in HTML
generation because it is not exactly XML. (For example, most browsers
will break if you XML-encode Javascript strings.)

Jay

On Wed, Nov 10, 2010 at 1:45 AM, YC <yinso.chen at gmail.com> wrote:
> What do you think of changing the behavior so that the cdata-string contains
> data without the cdata section wrapper?
> It looks like the two main code are as follows:
>
> ;; /collects/xml/private/reader.rkt
> (define (lex-tag-cdata-pi-comment in pos)
>   ...
>          [(#\[) (read-char in)
>                 (unless (string=? (read-string 6 in) "CDATA[")
>                   (lex-error in pos "expected CDATA following <["))
>                 (let ([data (lex-cdata-contents in pos)])
>                   (make-cdata start (pos) (format "<![CDATA[~a]]>" data)))]
> ;; /collects/xml/private/writer.rkt
> ;; write-xml-cdata : Cdata Nat (Nat Output-Stream -> Void) Output-Stream ->
> Void
> (define (write-xml-cdata cdata over dent out)
>   ;; XXX: Different kind of quote is needed, for assume the user includes
> the <![CDATA[...]]> with proper quoting
>   (write-xml-base (format "~a" (cdata-string cdata)) over dent out))
>
> So the reader already parse out the cdata without the wrapper, but add it
> back it for whatever reason.  Perhaps switching the two?
> Grepping through the collects dir and the following uses make-cdata besides
> xml/private/reader.rkt:
>
> /Applications/plt-5.0/collects/scribble/html-render.rkt:
>
> (lambda strings (xml:make-cdata loc loc (string-append* strings)))))
>
> /Applications/plt-5.0/collects/web-server/default-web-root/htdocs/servlets/examples/template-xexpr.rkt:
>
>
> ,(make-cdata #f #f (include-template "static.html"))))
>
> /Applications/plt-5.0/collects/web-server/private/xexpr.rkt:
>
>
> ,(make-cdata #f #f (format-xexpr/errors val))))))])
>
> and these do not look like they provide their own <![CDATA[...]]> as
> instructed in the cdata documentation.
> Thoughts?  Thanks,
> yc
> On Tue, Nov 9, 2010 at 9:06 PM, Jay McCarthy <jay.mccarthy at gmail.com> wrote:
>>
>> It is documented that way:
>>
>>
>> http://docs.racket-lang.org/xml/index.html#(def._((lib._xml/main..rkt)._cdata))
>>
>> I'm not sure why it was originally written that way.
>>
>



-- 
Jay McCarthy <jay at cs.byu.edu>
Assistant Professor / Brigham Young University
http://faculty.cs.byu.edu/~jay

"The glory of God is Intelligence" - D&C 93


Posted on the users mailing list.