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

Ampersand in string literal of XML node.

7 replies
tim.stokes
Joined: 2011-02-22,
User offline. Last seen 1 year 19 weeks ago.

Why can't I have this?

val link =

The compiler does not like the ampersand in the string.

tim.stokes
Joined: 2011-02-22,
User offline. Last seen 1 year 19 weeks ago.
Re: Ampersand in string literal of XML node.

If I turn it into a special character then it compiles.

val link =

But that doesn't help me.

Is this a bug?

On Jun 23, 2:23 pm, Tim Stokes wrote:
> Why can't I have this?
>
> val link =
>
> The compiler does not like the ampersand in the string.

tim.stokes
Joined: 2011-02-22,
User offline. Last seen 1 year 19 weeks ago.
Re: Ampersand in string literal of XML node.

So if I use:

val link =

Then I actually get the right thing but it doesn't scan well from a
templating point of view.

Any chance this could be fixed or is it invalid XML?

On Jun 23, 2:26 pm, Tim Stokes wrote:
> If I turn it into a special character then it compiles.
>
> val link =
>
> But that doesn't help me.
>
> Is this a bug?
>
> On Jun 23, 2:23 pm, Tim Stokes wrote:
>
>
>
>
>
>
>
> > Why can't I have this?
>
> > val link =
>
> > The compiler does not like the ampersand in the string.

Erik Peterson
Joined: 2010-08-02,
User offline. Last seen 42 years 45 weeks ago.
Re: Re: Ampersand in string literal of XML node.

Valid:

See http://www.w3schools.com/XML/xml_validator.asp

What do you mean by "it doesn't scan well"?

On Jun 23, 2011, at 2:30 PM, Tim Stokes wrote:

> So if I use:
>
> val link =
>
> Then I actually get the right thing but it doesn't scan well from a
> templating point of view.
>
> Any chance this could be fixed or is it invalid XML?
>
> On Jun 23, 2:26 pm, Tim Stokes wrote:
>> If I turn it into a special character then it compiles.
>>
>> val link =
>>
>> But that doesn't help me.
>>
>> Is this a bug?
>>
>> On Jun 23, 2:23 pm, Tim Stokes wrote:
>>
>>
>>
>>
>>
>>
>>
>>> Why can't I have this?
>>
>>> val link =
>>
>>> The compiler does not like the ampersand in the string.

Erik Peterson
m: (281) 804-9023
ep@ardec.com

tim.stokes
Joined: 2011-02-22,
User offline. Last seen 1 year 19 weeks ago.
Re: Re: Ampersand in string literal of XML node.

I mean it doesn't read easily for people who are used to seeing just '&'

On 23 June 2011 14:46, coach3pete wrote:
> Invalid:
>
>
> Valid:
>
>
> See http://www.w3schools.com/XML/xml_validator.asp
>
> What do you mean by "it doesn't scan well"?
>
>
> On Jun 23, 2011, at 2:30 PM, Tim Stokes wrote:
>
>> So if I use:
>>
>> val link =
>>
>> Then I actually get the right thing but it doesn't scan well from a
>> templating point of view.
>>
>> Any chance this could be fixed or is it invalid XML?
>>
>> On Jun 23, 2:26 pm, Tim Stokes wrote:
>>> If I turn it into a special character then it compiles.
>>>
>>> val link =
>>>
>>> But that doesn't help me.
>>>
>>> Is this a bug?
>>>
>>> On Jun 23, 2:23 pm, Tim Stokes wrote:
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>> Why can't I have this?
>>>
>>>> val link =
>>>
>>>> The compiler does not like the ampersand in the string.
>
> Erik Peterson
> m: (281) 804-9023
> ep@ardec.com
>
>
>
>

Lars Hupel
Joined: 2010-06-23,
User offline. Last seen 44 weeks 3 days ago.
Re: Ampersand in string literal of XML node.

That's why it's generally a good idea to avoid & for separation of
parameters. If you control the application, better choose ; or something
else (which is recommended by the W3C IIRC).

Martin S. Weber
Joined: 2008-12-23,
User offline. Last seen 42 years 45 weeks ago.
Re: Ampersand in string literal of XML node.

On 06/23/11 16:23, Tim Stokes wrote:
> Why can't I have this?
>
> val link =
>
> The compiler does not like the ampersand in the string.

It's not valid XML.

Compare the following quote from section 2.4 from the xml spec:

"The ampersand character (&) and the left angle bracket (<) MUST NOT appear in
their literal form, except when used as markup delimiters, or within a
comment, a processing instruction, or a CDATA section. If they are needed
elsewhere, they MUST be escaped using either numeric character references or
the strings " & " and " < " respectively. The right angle bracket (>)
may be represented using the string " > ", and MUST, for compatibility, be
escaped using either " > " or a character reference when it appears in the
string " ]]> " in content, when that string is not marking the end of a CDATA
section."

from: http://www.w3.org/TR/2008/REC-xml-20081126/#syntax

I know it sucks, but so does XML.

Have a great existence,

-Martin

Erik Peterson
Joined: 2010-08-02,
User offline. Last seen 42 years 45 weeks ago.
Re: Re: Ampersand in string literal of XML node.

I guessing a bit without knowing more context...but have you seen scalate for templating?
http://scalate.fusesource.org/documentation/jade.html

If you want something directly in a scala api consider creating a "searchLinkBuilder" using a case class with named params...or a fluent api: http://stackoverflow.com/questions/6347083/type-safe-builder-library-for...

On Jun 23, 2011, at 3:09 PM, Tim Stokes wrote:

> I mean it doesn't read easily for people who are used to seeing just '&'
>
> On 23 June 2011 14:46, coach3pete wrote:
>> Invalid:
>>
>>
>> Valid:
>>
>>
>> See http://www.w3schools.com/XML/xml_validator.asp
>>
>> What do you mean by "it doesn't scan well"?
>>
>>
>> On Jun 23, 2011, at 2:30 PM, Tim Stokes wrote:
>>
>>> So if I use:
>>>
>>> val link =
>>>
>>> Then I actually get the right thing but it doesn't scan well from a
>>> templating point of view.
>>>
>>> Any chance this could be fixed or is it invalid XML?
>>>
>>> On Jun 23, 2:26 pm, Tim Stokes wrote:
>>>> If I turn it into a special character then it compiles.
>>>>
>>>> val link =
>>>>
>>>> But that doesn't help me.
>>>>
>>>> Is this a bug?
>>>>
>>>> On Jun 23, 2:23 pm, Tim Stokes wrote:
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>> Why can't I have this?
>>>>
>>>>> val link =
>>>>
>>>>> The compiler does not like the ampersand in the string.
>>

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