私は、Playフレームワークによって駆動されるwebapp内に単純なエンティティを持っています。Play framework:モデル化するXMLを解析する
case class MyItem(id: Option[Long] = None, name: String, comments: List[Comment])
case class Comment(commentDate: Date, commentText: String)
そして、私はこのようになりますDBからXMLを取得:それはこのようになります
<?xml version="1.0"?>
<item>
<id>1</id>
<name>real item</name>
<comments>
<comment>
<comment_date>01.01.1970</comment_date>
<comment_text>it rocks</comment_text>
</comment>
<comment>
<comment_date>02.01.1970</comment_date>
<comment_text>it's terrible</comment_text>
</comment>
</comments>
</item>
をそして今、私はモデルとフォームのマッピングにそれを解析するとは考えています。
マイフォームマッピング念のために(今コンパイルされません):
val itemForm = Form(
mapping(
"id" -> optional(longNumber),
"name" -> nonEmptyText,
"comments" -> list(mapping(
"commentDate" -> date("dd.mm.yyyy"),
"commentText" -> text
)(Comment.apply)(Comment.unapply))
)(MyItem.apply)(MyItem.unapply)
)