我正在寻找这样的文档:
<root/>
我可以以编程方式添加孩子。从理论上讲,它看起来像这样:
val root_node_name = "root"
val doc = <{root_node_name}/>
但这似乎不起作用:
error: not found: value <
所以,我尝试的是这样的:
val root_node_name = "root"
val doc = new scala.xml.Elem(null, root_node_name, null, scala.xml.TopScope, null)
编译但在运行时我得到这个空指针异常:
java.lang.NullPointerException
at scala.xml.Utility$.toXML(Utility.scala:201)
at scala.xml.Utility$$anonfun$sequenceToXML$2.apply(Utility.scala:235)
at scala.xml.Utility$$anonfun$sequenceToXML$2.apply(Utility.scala:235)
at scala.Iterator$class.foreach(Iterator.scala:414)
at scala.runtime.BoxedArray$AnyIterator.foreach(BoxedArray.scala:45)
at scala.Iterable$class.foreach(Iterable...
我正在使用 Scala 2.8。有什么例子可以说明如何做到这一点?谢谢。