用自定义命名空间解析Ruby中的ATOM
问题描述:
我试图读取这个ATOM Feed(http://ffffound.com/feed),但我无法获得任何定义为命名空间的一部分的值,例如媒体:内容和媒体:缩略图。用自定义命名空间解析Ruby中的ATOM
我需要让分析器知道名称空间吗?
这里就是我已经得到了:
require 'rss/2.0'
require 'open-uri'
source = "http://ffffound.com/feed"
content = ""
open(source) do |s| content = s.read end
rss = RSS::Parser.parse(content, false)
答
我相信你将不得不使用的libxml-红宝石为。
gem 'libxml-ruby', '>= 0.8.3'
require 'xml'
xml = open("http://ffffound.com/feed")
parser = XML::Parser.string(xml, :options =>XML::Parser::Options::RECOVER)
doc = parser.parse
doc.find("channel").first.find("items").each do |item|
puts item.find("media:content").first
#and just guessing you want that url thingy
puts item.find("media:content").first.attributes.get_attribute("url").value
end
我希望您指出正确的方向。