在 GitHub 上編輯此頁面

已移除:XML 文字

XML 文字仍受支援,但將在不久的將來移除,並改用 XML 字串內插

import dotty.xml.interpolator.*

case class Person(name: String) { override def toString = name }

@main def test: Unit =
  val bill = Person("Bill")
  val john = Person("John")
  val mike = Person("Mike")
  val todoList = List(
    (bill, john, "Meeting", "Room 203, 11:00am"),
    (john, mike, "Holiday", "March 22-24")
  )
  // XML literals (to be dropped)
  val mails1 = for (from, to, heading, body) <- todoList yield
    <message>
      <from>{from}</from><to>{to}</to>
      <heading>{heading}</heading><body>{body}</body>
    </message>
  println(mails1)
  // XML string interpolation
  val mails2 = for (from, to, heading, body) <- todoList yield xml"""
    <message>
      <from>${from}</from><to>${to}</to>
      <heading>${heading}</heading><body>${body}</body>
    </message>"""
  println(mails2)

如需更多資訊,請參閱 Yassin Kammoun (2019) 的學期專案 Dotty 的 XML 字串內插程式