哪些插件或宝石可用于将xml转换为csv文件?
答案 0 :(得分:7)
答案 1 :(得分:0)
在Rails中使用Nokogiri。
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"