Practical Hpricot: XML to INI
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
require 'hpricot' require 'open-uri' def ini_entry(url, name) buffer = "[#{url}]\\n" buffer += "name = #{name}\\n" buffer += "\\n" buffer end doc = Hpricot(open("http://www.byteclub.net/testsite/getFeeds.php")) (doc/"blog").each do |elem| url = (elem/"url") name = (elem/"name") comments = (elem/"comments") if name.length > 0 puts ini_entry(url.inner_text, name.inner_text) if url.inner_text.length > 0 puts ini_entry(comments.inner_text, name.inner_text + " Comments") if comments.inner_text.length > 0 end end |
Planet coming soon!