以下代碼(從a question from about a year ago複製而來)在Scala 2.7.7下正常工作,但在Scala 2.8.0(Beta 1,RC8)下無法正常工作。如何在Scala中將二維數組寫入xml 2.8.0
import scala.xml
class Person(name : String, age : Int) {
def toXml(): xml.Elem =
<person><name>{ name }</name><age>{ age }</age></person>
}
def peopleToXml(people: Array[Person]): xml.Elem = {
<people>{ for {person <- people} yield person.toXml }</people>
}
val data = Array(new Person("joe",40), new Person("mary", 35))
println(peopleToXml(data))
(根據2.7.7)的輸出應該是:
<people><person><name>joe</name><age>40</age></person><person><name>mary</name><age>35</age></person></people>
而是出來爲:
<people>\[Lscala.xml.Elem;@17821782</people>
我如何得到這個行爲就像它在2.7.x中所做的那樣?
謝謝邁克爾,這將很好地工作。 – Shadowlands 2010-04-22 06:19:32