Reputation: 16339
Which plugins or gems are available to convert xml to csv file ?
Upvotes: 2
Views: 1628
Reputation: 337
Using Nokogiri in Rails.
xml_file = "datafile.xml"
doc = Nokogiri::XML.parse(xml_file)
output = "data.csv"
sv_string = CSV.generate do |csv|
# header row
csv << ['header_array']
# data rows
@object_array.map do |object|
csv << [object['NODE_NAME'].text]
end
end
#send response
send_data csv_string,
:type => 'text/csv; charset=iso-8859-1; header=present',
:disposition => "attachment; filename=users.csv"
Upvotes: 0