From: Michelle Col Date: 2012-09-07T10:29:55+09:00 Subject: Re: Parsing through downloaded html "Иван Бишевац" wrote in post #1074911: > I've done similar job recently. I've copied part of code so look at it > maybe it could help you: > require 'nokogiri' > require 'spreadsheet' > > class XmlParsing > def test > row = 0 > column = 0 > book = Spreadsheet::Workbook.new > sheet = book.create_worksheet > > Dir.chdir("xml") > puts Dir.pwd > Dir.glob("*.xml") do |file| > f = File.open(file) > doc = Nokogiri::XML(f) > fullname_node = doc.at_xpath("//full_name") > sheet[row,column] = fullname_node.content > f.close > row += 1 > end > book.write 'spreadsheet.xls' > end > end > > xml = XmlParsing.new > xml.test > > > I'm not sure if it works because I've deleted some code from original > script but this is general idea. It script parses xml document and puts > information into excel. > > Plus you need spreadsheet gem. You can install it with: > sudo gem install spreadsheet. > > Or there is better way to do it. Make one file named Gemfile and put > this > content into it: > source 'https://rubygems.org' > > gem 'nokogiri' > gem 'spreadsheet' > > Save file and go to console cd to dir where Gemfile is located and run: > bundle install > > This is preferred way to go because there is no need to install gems one > by > one manually. Instead when you want to run your software on different > machine you just invoke bundle install. > > Hope it helps. > > 2012/9/6 Sybren Kooistra Good stuff! This ran nicely with the exception of "content" element generating a nil exception but my XML file was not compliant to XML rules. Ruby is a nice language for beginners. I am new user for 1 day now and I have learned so much from everyone! Try to avoid saying that you are new. This is due to a user named Ryan Daves. He talks very negative to users who do that. Also another ruby forum you might want to reference is at tek-tips.com. The users are helpful there as well. Good luck. -Michelle -- Posted via http://www.ruby-forum.com/.