[racket] read-xml: lex-error when reading Javascript

From: Matthew Butterick (mb at mbtype.com)
Date: Fri May 2 17:46:45 EDT 2014

The handling of <script> and <style> tags is a notable difference between XML & HTML. If you want your HTML to be usable as XML, then you have to enclose the contents of any <script> or <style> tag in a CDATA tag. (Whereas HTML parsers assume this is true by default — in that case, CDATA tags aren't wrong, they're just unnecessary.)

If your HTML template is a static file, you can just put the CDATA tags in manually.

If you're using x-expressions to generate the HTML, the xexpr->html function in my txexpr library is a replacement for xexpr->string that will add the CDATA tags.

raco pkg install txexpr



On Apr 25, 2014, at 1:01 PM, Alegria Baquero <alegriabaquero at gmail.com> wrote:

> Hello,
> 
> I am using the web-server/servlet library to deploy an html:
> 
> (let ((start (lambda (req) 
>                  (response/xexpr 
>                   (string->xexpr (include-template "ui/page.html"))))))
> 
> 
> Page.html includes Javascript code and everything works well until I try to use a comparison operator.  So for example, when read-xml tries to read the javascript for loop
> 
> for (var i=0;i<nodeList.length;i++) {
>                     alert("hello");
>                 }
> 
> It gives the following error:
> 
> read-xml: lex-error: at position 42.59/1747: expected / or > to close tag `nodeList.length'
> 
> It turns out it believes the operator '<' is an opening xml tag.
> 
> Has anyone found a way to fix/circumvent this problem?
> 
> Thanks a lot.
> 
> 
> ____________________
>  Racket Users list:
>  http://lists.racket-lang.org/users



Posted on the users mailing list.