我希望以下代码生成具有以下内容的 XML 值:
<TestInteger value="10"/>
编译器给出错误
scala> import scala.xml._
import scala.xml._
scala> val x:Int = 10
x: Int = 10
scala> <TestInteger value={x}/>
<console>:8: error: overloaded method constructor UnprefixedAttribute with alternatives (String,Option[Seq[scala.xml.Node]],scala.xml.MetaData)scala.xml.UnprefixedAttribute <and> (String,String,scala.xml.MetaData)scala.xml.UnprefixedAttribute <and> (String,Seq[scala.xml.Node],scala.xml.MetaData)scala.xml.UnprefixedAttribute cannot be applied to (java.lang.String,Int,scala.xml.MetaData)
<TestInteger value={x}/>
我究竟做错了什么?XML 中是否允许使用整数文字?
我正在使用 Scala 2.7.7