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

injecting attribute values into xml nodes?

1 reply
Todd Cook
Joined: 2009-05-18,
User offline. Last seen 42 years 45 weeks ago.

Is there a way to inject attribute values into the node elements?, e.g.

The following works:

scala> (1980 to 2009).toList.map(_.toString).reverse.map( v =>
""+{v}+"" )

res1: List[java.lang.String] = List(2009, 2008, 2007, 2006,
2005, 2004, 2003, 2002, 2001,
2000 (1980 to 2009).toList.map(_.toString).reverse.map( v =>
{v} )
:1: error: in XML literal: ' or " delimited attribute value
or '{' scala-expr '}' expected
(1980 to 2009).toList.map(_.toString).reverse.map( v =>
{v} )

^
:1: error: in XML literal: whitespace expected
(1980 to 2009).toList.map(_.toString).reverse.map( v =>
{v} )

Todd

David Pollak
Joined: 2008-12-16,
User offline. Last seen 42 years 45 weeks ago.
Re: injecting attribute values into xml nodes?
(1980 to 2009).toList.map(_.toString).reverse.map( v => <option value={v}>{v}</option> ) 

On Thu, May 21, 2009 at 8:24 PM, Todd Cook <todd [at] cookconsulting [dot] com> wrote:
Is there a way to inject attribute values into the node elements?, e.g.

The following works:

scala> (1980 to 2009).toList.map(_.toString).reverse.map( v => "<option value=\""+{v}+"\">"+{v}+"</option>" )

res1: List[java.lang.String] = List(<option value="2009">2009</option>, <option value="2008">2008</option>, <option value="2007">2007</option>, <option value="2006">2006</option>, <option value="2005">2005</option>, <option value="2004">2004</option>, <option value="2003">2003</option>, <option value="2002">2002</option>, <option value="2001">2001</option>, <option value="2000">2000</...

The following doesn't:

scala> (1980 to 2009).toList.map(_.toString).reverse.map( v => <option value=\"{v}\">{v}</option> )
<console>:1: error: in XML literal: ' or " delimited attribute value or '{' scala-expr '}' expected
      (1980 to 2009).toList.map(_.toString).reverse.map( v => <option value=\"{v}\">{v}</option> )
                                                                          ^
<console>:1: error: in XML literal: whitespace expected
      (1980 to 2009).toList.map(_.toString).reverse.map( v => <option value=\"{v}\">{v}</option> )


Todd




--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Git some: http://github.com/dpp

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