2010-07-31 29 views
1

我試圖讀取這個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) 

回答

1

我相信你將不得不使用的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 

我希望您指出正確的方向。