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 <[email protected]>
> Hi Ivan, thanks.
>
> I'm doing my best here, and I do search before I post. I was just
> checking if I was working in the right direction. Excel library is step
> two.
>
> --
> Posted via http://www.ruby-forum.com/.
>
>
-- You received this message because you are subscribed to the Google Groups
ruby-talk-google group. To post to this group, send email to
[email protected]. To unsubscribe from this group, send email
to [email protected]. For more options, visit this
group at https://groups.google.com/d/forum/ruby-talk-google?hl=en