无法使用Retrofit2解析rss feed xml内容

时间:2018-12-04 09:16:41

标签: android kotlin retrofit2

这是我的网站rss feed结构。尝试使用Retrofit2 XML Convert Factory对此进行解析。

<rss>
   <channel>
      <item>
         <title></title>
         <link></link>
      </item>
      <item>
         <title></title>
         <link></link>
      </item>
   </channel>
</rss>

总是出现以下错误:

  

org.simpleframework.xml.core.ElementException:元素“ title”在com.example.android.model.FeedChannel类的第-1行不匹配

这是我的数据类:

@Root(name = "rss", strict = false)
data class FeedChannelData @JvmOverloads constructor(
    @field:Element(name = "channel")
    @param:Element(name = "channel")
    val feedChannel: FeedChannel? = null
)

@Root(name = "channel", strict = true)
data class FeedChannel @JvmOverloads constructor(
    @field:ElementList(name ="item", inline = true)
    @param:ElementList(name ="item", inline = true)
    var itemList: List<Item>? = null
)

@Root(name = "item", strict = false)
data class Item @JvmOverloads constructor(

    @field:Element(name = "title", required = true)
    @param:Element(name = "title", required = true)
    val title: String = "",

    @field:Element(name = "link", required = true)
    @param:Element(name = "link", required = true)
    val link: String= ""
)

0 个答案:

没有答案