开发者

Scala XML: create a node not using literals

开发者 https://www.devze.com 2022-12-25 01:25 出处:网络
How can I create a node in Scala without using literals? What I need is to set the node tag name in runtime, for example:

How can I create a node in Scala without using literals?

What I need is to set the node tag name in runtime, for example:

var tag = 开发者_C百科"post"
var content = "234"

How can I get a node <post>234</post>?


On Scala 2.8:

<xml>{content}</xml>.copy(label = tag)


scala> import xml._
import xml._

scala> def textElem(name: String, text: String) =  Elem(null, name, Null, TopScope, Text(text)) 
textElem: (name: String,text: String)scala.xml.Elem

scala> textElem("foo", "bar")                                                                   
res0: scala.xml.Elem = <foo>bar</foo>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号