Embedded code in XML

24 views
Skip to first unread message

Cay Horstmann

unread,
Oct 1, 2011, 11:13:12 AM10/1/11
to scala-l...@googlegroups.com
The "Programming in Scala" book by Odersky, Spoon and Venners has this to say about code inside XML:

An expression inside a brace escape does not have to evaluate to an XML
node. It can evaluate to any Scala value. In such a case, the result is converted
to a string and inserted as a text node.

That is false, as one can easily see:

 <li>{42}</li>.child(0).getClass // it's an Atom[Int], not a Text node

Nodes don't get wrapped into atoms:

<li>{<p/>}</li>.child(0).getClass // It's an Elem

I expected that strings get wrapped into Text nodes, but it turns out that's not so.

<li>{"Fred"}</li>.child(0).getClass // It's an Atom[String]

This may be a fine point, but I am wondering where this is specified. Chapter 10 of the language reference doesn't have a lot of detail.

Thanks,

Cay
Reply all
Reply to author
Forward
0 new messages