- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
XML literals - starting with some curly braces
Sat, 2010-01-16, 01:49
hi,
i would like to use the XML literals but have come across this problem:
trait SessionElement {
def name: String
def toXML: scala.xml.Elem
}
trait SessionElementSeq[ T <: SessionElement ] extends SessionElement {
def elements: List[ T ]
def toXML =
<{name}>
{elements.map(_.toXML)}
}
... here i cannot start the literal using scala code (function 'name')... any chance to overcome this?
thanks, -sciss-
Sat, 2010-01-16, 02:37
#2
Re: XML literals - starting with some curly braces
ok, a pity.
also it's nice to have the \\ attribute extractor. but... there is no way to serialize into attributes it seems:
scala> val age = 32
age: Int = 32
scala> val joe =
:5: error: overloaded method constructor UnprefixedAttribute with alternatives (key: String,value: Option[Seq[scala.xml.Node]],next: scala.xml.MetaData)scala.xml.UnprefixedAttribute (key: String,value: String,next: scala.xml.MetaData)scala.xml.UnprefixedAttribute (key: String,value: Seq[scala.xml.Node],next1: scala.xml.MetaData)scala.xml.UnprefixedAttribute cannot be applied to (java.lang.String,Int,scala.xml.MetaData)
val joe =
> As I understand it the element label has to be a constant when using an XML
> literal. You will have to invoke the Elem constructor explicitly.
>
Sat, 2010-01-16, 02:47
#3
Re: XML literals - starting with some curly braces
On Fri, Jan 15, 2010 at 5:26 PM, Sciss wrote:
> ok, a pity.
>
> also it's nice to have the \\ attribute extractor. but... there is no way to serialize into attributes it seems:
>
> scala> val age = 32
> age: Int = 32
>
> scala> val joe = | name = "Joe"
> | rank = "code monkey"
> | age = {age}
> | />
> :5: error: overloaded method constructor UnprefixedAttribute with alternatives (key: String,value: Option[Seq[scala.xml.Node]],next: scala.xml.MetaData)scala.xml.UnprefixedAttribute (key: String,value: String,next: scala.xml.MetaData)scala.xml.UnprefixedAttribute (key: String,value: Seq[scala.xml.Node],next1: scala.xml.MetaData)scala.xml.UnprefixedAttribute cannot be applied to (java.lang.String,Int,scala.xml.MetaData)
> val joe = ^
>
This error at least is just because age needs to be a string:
scala> val age = 32.toString
age: java.lang.String = 32
scala> val joe =
joe: scala.xml.Elem =
As I understand it the element label has to be a constant when using an XML
literal. You will have to invoke the Elem constructor explicitly.