Skip to content

Instantly share code, notes, and snippets.

@HusseinMorsy
Created January 15, 2010 12:40
Show Gist options
  • Save HusseinMorsy/278020 to your computer and use it in GitHub Desktop.
Save HusseinMorsy/278020 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'nokogiri'
require 'open-uri'
# remove xmlns="http://www.blinksale.com/api from xml document to work
file_name = "blinksale-data.xml"
file =File.open(file_name, 'r')
# Get a Nokogiri::HTML:Document for the page we’re interested in...
doc = Nokogiri::XML(file)
# Do funky things with it using Nokogiri::XML::Node methods...
#
# <invoices>
# <invoice>
# <client>
# #....
# </client>
# </invoice>
# </invoices>
doc.xpath("//invoice").each do |invoice|
customer = invoice.xpath('client').first['name']
nr = invoice.xpath('number').first.content
date = invoice.xpath('date').first.content
total = invoice['total']
total_de = total.gsub(".",",")
puts %(#{nr},#{date},"#{total_de}","#{customer}")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment