This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Ampersands are escaped inside <![CDATA[ ... ]]> literals.

4 replies
Dmitry Grigoriev
Joined: 2009-07-12,
User offline. Last seen 42 years 45 weeks ago.

Hello everyone.

I'd like to write javascript code inside XML literals. But I get:

scala> val x =
x: scala.xml.Elem = Hello & world

This is 2.8.0.RC1. Is that correct? I'm not sure about W3C specs but
CDATA is a most common way to escape javascript code to maintain HTML
validness:

//

Same happens when I use scala.xml.PCData. So I can use only
scala.xml.Unparsed.

David Pollak
Joined: 2008-12-16,
User offline. Last seen 42 years 45 weeks ago.
Re: Ampersands are escaped inside <![CDATA[ ... ]]> literals.
Yeah, this is a problem with Scala not liking CDATA.  The discussion/debate about this goes back more than 3 years.  In Lift-land, we implemented our own parser for XML and our own tool to emit XML correctly (preserving CDATA).  That code is in lift-util and you're welcome to it.  There's not much that can be done with the compiler.

Sorry.

On Wed, Apr 28, 2010 at 8:41 AM, Dmitry Grigoriev <mail@dimgel.ru> wrote:
Hello everyone.

I'd like to write javascript code inside XML literals. But I get:

scala> val x = <td><![CDATA[ Hello & world ]]></td>
x: scala.xml.Elem = <td> Hello &amp; world </td>

This is 2.8.0.RC1. Is that correct? I'm not sure about W3C specs but
CDATA is a most common way to escape javascript code to maintain HTML
validness:

<script type="text/javascript">
       // <![CDATA[
       ...
       // ]]>
</script>

Same happens when I use scala.xml.PCData. So I can use only
scala.xml.Unparsed.

--
Cheers,
dimgel

http://dimgel.ru/lib.web
Thin, stateless, strictly typed Scala web framework.




--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Surf the harmonics
Dmitry Grigoriev
Joined: 2009-07-12,
User offline. Last seen 42 years 45 weeks ago.
Re: Ampersands are escaped inside <![CDATA[ ... ]]> literals.

On 04/28/2010 07:46 PM, David Pollak wrote:
> Yeah, this is a problem with Scala not liking CDATA. The
> discussion/debate about this goes back more than 3 years. In Lift-land,
> we implemented our own parser for XML and our own tool to emit XML
> correctly (preserving CDATA). That code is in lift-util and you're
> welcome to it. There's not much that can be done with the compiler.

Hm, then it's obviously a compiler bug. Why guys keep it unfixed? I use
scala's XML literals (not external templates) so external XML
parser/serializer is no way, unfortunately.

extempore
Joined: 2008-12-17,
User offline. Last seen 35 weeks 3 days ago.
Re: Re: Ampersands are escaped inside <![CDATA[ ... ]]> literal

On Wed, Apr 28, 2010 at 07:54:50PM +0400, Dmitry Grigoriev wrote:
> Hm, then it's obviously a compiler bug. Why guys keep it unfixed? I
> use scala's XML literals (not external templates) so external XML
> parser/serializer is no way, unfortunately.

If it's "obviously" a compiler bug I will fix it. Is it? If it's
unfixed to this point I assume someone thinks otherwise. I find that
when I try to find out about such things, I often either get no answer
or multiple-page specification legalese about why some or other
undesirable behavior is a critical feature of xml conformance.

In other words, I'm willing to fix XML code but I'm unwilling to resolve
any ambiguities about what fix if any is the correct one.

Dmitry Grigoriev
Joined: 2009-07-12,
User offline. Last seen 42 years 45 weeks ago.
Re: Ampersands are escaped inside <![CDATA[ ... ]]> literals.

On 04/28/2010 08:07 PM, Paul Phillips wrote:
> In other words, I'm willing to fix XML code but I'm unwilling to resolve
> any ambiguities about what fix if any is the correct one.

Since I promised to answer to you here, I afford one more message to
scala@ ML. I explained situation here:
https://lampsvn.epfl.ch/trac/scala/ticket/3368#comment:1

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland