xml – Scala填充模板的方式?

Ruby中我可以这样:
string=<<EOTEMPLATE
<root>
  <hello>
     <to>%s</to>
     <message>welcome mr %s</message>
  </hello>
  ...
</root>
EOTEMPLATE

当我想“渲染”模板时,我会这样做:

rendered = string % ["me@mail.com","Anderson"]

它将使用数组中传递的值填充模板.有没有办法在Scala中执行此操作,而不是使用Java的String.format?如果我在Scala中写这个:

val myStr = <root>
<hello>
<to>{address}</to>
<message>{message}</message>
</hello>
</root>

生成的XML已经“填充”了.有没有办法可以“模板化”XML?

使用函数和Scala的XML:
val tmpl = {(address: String,message: String) =>
  <root>
    <hello>
      <to>{address}</to>
      <message>{message}</message>
    </hello>
  </root>
  }

和:

tmpl("me@mail.com","Anderson")

一些糖:

def tmpl(f: Product => Elem) = new {
   def %(args: Product) = f(args)
}

val t = tmpl{case (address,message) => 
  <root>
    <hello>
      <to>{address}</to>
      <message>{message}</message>
    </hello>
  </root>
}

t % ("me@mail.com","Anderson")

相关文章

php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念