为xml创建Kotlin数据类

oknwwptz  于 2022-11-16  发布在  Kotlin
关注(0)|答案(1)|浏览(118)

有谁能帮助创建一个Kotlin数据类,以便与Retrofit和Simplexml转换器一起使用,用于这个看似简单的xml吗?

  1. <texts>
  2. <text id="3">
  3. <title>Veðurhorfur á höfuðborgarsvæðinu</title>
  4. <creation>2022-11-03 10:20:30</creation>
  5. <valid_from>2022-11-03 12:00:00</valid_from>
  6. <valid_to>2022-11-05 00:00:00</valid_to>
  7. <content>Norðlæg </content>
  8. </text>
  9. <text id="6">
  10. <title>Veðurhorfur</title>
  11. <creation>2022-11-03 08:41:53</creation>
  12. <valid_from>2022-11-05 12:00:00</valid_from>
  13. <valid_to>2022-11-10 12:00:00</valid_to>
  14. <content>Austan- </content>
  15. </text>
  16. </texts>
laximzn5

laximzn51#

基于this article,应执行以下操作:

  1. @Root(name = "texts", strict = false)
  2. class Texts @JvmOverloads constructor(
  3. @field:ElementList(inline = true)
  4. var textList: List<Text>? = null
  5. )
  6. @Root(name = "text", strict = false)
  7. class Text @JvmOverloads constructor(
  8. @field:Attribute(name = "id")
  9. var id: String = "",
  10. @field:Element(name = "title")
  11. var title: String = "",
  12. @field:Element(name = "creation")
  13. var creation: String = "",
  14. @field:Element(name = "valid_from")
  15. var validFrom: String = "",
  16. @field:Element(name = "valid_to")
  17. var validTo: String = "",
  18. @field:Element(name = "content")
  19. var content: String = "",
  20. )
展开查看全部

相关问题