Reputation: 745
I'm trying to parse some podcast xml feeds, but can not get all categories and other multiple fields that have the same name.
Feed example: http://demo3984434.mockable.io/cast
<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:itunesu="http://www.itunesu.com/feed" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
<channel>
<title>Podcast Title</title>
<link>http://link.com</link>
<language>en-us</language>
<itunes:subtitle>Subtitle!!!</itunes:subtitle>
<itunes:author>Author Name</itunes:author>
<media:category scheme="http://www.itunes.com/dtds/podcast-1.0.dtd">Comedy</media:category>
<media:category scheme="http://www.itunes.com/dtds/podcast-1.0.dtd">Society & Culture</media:category>
<media:category scheme="http://www.itunes.com/dtds/podcast-1.0.dtd">Games & Hobbies/Video Games</media:category>
<media:category scheme="http://www.itunes.com/dtds/podcast-1.0.dtd">TV & Film</media:category>
<media:category scheme="http://www.itunes.com/dtds/podcast-1.0.dtd">Music</media:category>
<itunes:category text="Comedy"/>
<itunes:category text="Society & Culture"/>
<itunes:category text="Games & Hobbies"/>
<itunes:category text="Video Games"/>
<itunes:category text="TV & Film"/>
<itunes:category text="Music"/>
</channel>
</rss>
RSSFeed.kt:
@Root(name = "rss", strict = false)
class RSSFeed {
@field:Element(name = "channel")
var mFeedChannel: FeedChannel? = null
}
FeedChannel.kt
@Root(name = "channel", strict = false)
open class FeedChannel {
@field:Element(name = "title")
var mTitle: String? = null
@field:Element(name = "link")
var mLink: String? = null
@field:Element(name = "subtitle")
var mSubtitle: String? = null
@field:Element(name = "author")
var mAuthor: String? = null
@field:ElementList(entry = "category", inline = true)
var mCategories: List<Category>? = null
@Root(name = "category", strict = false)
class Category {
@field:Element(name = "category")
var category: String? = null
}
}
But the categories list elements are always null:
Upvotes: 3
Views: 1671
Reputation: 745
Found the solution:
Changed the @field:Element fields and used String for instead of another class Category. Thanks to @DaveThomas
@Root(name = "channel", strict = false)
class FeedChannel {
@field:Element(name = "title")
var mTitle: String? = null
@field:Element(name = "link")
var mLink: String? = null
@field:Element(name = "subtitle")
var mSubtitle: String? = null
@field:Element(name = "author")
var mAuthor: String? = null
@field:ElementList(entry = "category", type = String::class, inline = true)
var mCategories: List<String>? = null
}
Upvotes: 1