scala xml系列化

来源:互联网 发布:安全生产网络知识竞赛 编辑:程序博客网 时间:2024/05/14 15:50

scala 从内部数据结构到xml的转化,目前要用的只有xml字面量和转义符

例如:

/** * xml 序列化 */abstract class CCTherm {  val description: String  val yearMade: Int  val dateObtained: String  val bookPrice: Int  val purchasePrice: Int  val condition: Int  override def toString = description  def toXML =    <cctherm>      <description>{description}</description>      <yearMade>{yearMade}</yearMade>      <dateObtained>{dateObtained}</dateObtained>      <bookPrice>{bookPrice}</bookPrice>      <purchasePrice>{purchasePrice}</purchasePrice>      <condition>{condition}</condition>    </cctherm>}object xmlTest {  def main(args: Array[String]): Unit = {    val therm = new CCTherm {                            val description = "hot dog #5"                            val yearMade = 1952                            val dateObtained = "March 14,2014"                            val bookPrice = 2199                            val purchasePrice = 500                            val condition = 9    }    println(therm.toXML)  }}

运行的结果

<cctherm>      <description>hot dog #5</description>      <yearMade>1952</yearMade>      <dateObtained>March 14,2014</dateObtained>      <bookPrice>2199</bookPrice>      <purchasePrice>500</purchasePrice>      <condition>9</condition>    </cctherm>
0 0
原创粉丝点击