使用自定义名称空间在Ruby中解析ATOM
我正在尝试读取此ATOM提要(),但无法获取任何定义为命名空间一部分的值,例如media:content和media:缩略图 我需要让解析器知道名称空间吗 以下是我得到的:使用自定义名称空间在Ruby中解析ATOM,ruby,parsing,namespaces,rss,atom-feed,Ruby,Parsing,Namespaces,Rss,Atom Feed,我正在尝试读取此ATOM提要(),但无法获取任何定义为命名空间一部分的值,例如media:content和media:缩略图 我需要让解析器知道名称空间吗 以下是我得到的: 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, f
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)
我相信您必须使用libxmlruby来实现这一点
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
我希望这能为您指明正确的方向。我相信您必须使用libxml-ruby
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
我希望这能为你指明正确的方向