我今天用scala一直在玩罗马1.0,虽然我已经能够获得标题,描述等标签,但它表示getContent()不存在。
val url = "http://www.codecommit.com/blog/ruby/monads-are-not-metaphors/feed"
val feed: SyndFeed = new SyndFeedInput().build(new XmlReader(new URL(url)))
var rss_title = feed.getTitle()
var rss_ex = feed.getTitleEx.getValue()
var rss_desc = feed.getDescription()
var rss_content = feed.getContent()
< ----虽然查看它应该有效的API,但这个似乎并不存在。
答案 0 :(得分:2)
feed表示多个条目,条目本身具有getContents()方法。这是一个完整的工作示例(假设您在类路径上有罗马1.0):
import com.sun.syndication.feed.synd.{SyndContent, SyndEntry, SyndFeed}
import com.sun.syndication.io.{SyndFeedInput, XmlReader}
import java.net.URL
import java.util.{List => JList}
import scala.collection.JavaConverters._
object RomeApp extends App {
val url = "http://www.codecommit.com/blog/ruby/monads-are-not-metaphors/feed"
val feed: SyndFeed = new SyndFeedInput().build(new XmlReader(new URL(url)))
val rss_title = feed.getTitle
val rss_ex = feed.getTitleEx.getValue
val rss_desc = feed.getDescription
val rss_entries = feed.getEntries.asInstanceOf[JList[SyndEntry]].asScala
for (entry <- rss_entries;
content <- entry.getContents.asInstanceOf[JList[SyndContent]].asScala) {
println("------------------------------")
println(content.getValue)
}
}
请注意,Java API中缺少泛型使得使用起来有点麻烦,库可能会使用一些拉皮条。