Created
January 15, 2010 12:40
-
-
Save HusseinMorsy/278020 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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