Subscribe: Parse ATOM in Ruby with custom namespaces - Stack Overflow
http://stackoverflow.com/feeds/question/3378176
Added By: Feedage Forager Feedage Grade B rated
Language: English
Tags:
atom ruby  content  custom namespaces  ffffound feed  media content  media  parse atom  parse  parser  ruby custom  ruby  xml 
Rate this Feed
Rate this feedRate this feedRate this feedRate this feedRate this feed
Rate this feed 1 starRate this feed 2 starRate this feed 3 starRate this feed 4 starRate this feed 5 star

Comments (0)

Feed Details and Statistics Feed Statistics
Preview: Parse ATOM in Ruby with custom namespaces - Stack Overflow

Parse ATOM in Ruby with custom namespaces - Stack Overflow



most recent 30 from stackoverflow.com



Updated: 2018-04-23T06:18:32Z

 



Parse ATOM in Ruby with custom namespaces

2017-05-07T04:41:24Z

I'm trying to read this ATOM Feed (http://ffffound.com/feed), but I'm unable to get to any of the values which are defined as part of the namespace e.g. media:content and media:thumbnail.

Do I need to make the parser aware of the namespaces?

Here's what I 've got:

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)



Answer by elmac for Parse ATOM in Ruby with custom namespaces

2017-05-07T04:41:24Z

I believe you would have to use libxml-ruby for that.

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

I hope that points you in the right direction.