Hi all!

I'm converting a csv file to an xml with the code below. This works
fine. Maybe it can be done differently and better but it works for me.

I have three questions:
1 - Why cant I re-use "csv" within "builder.type" ? If re-use it I dont
get any data.
2 - I would like to add an attribute to builder.type. How can do that? I
want the result to be like <type upgnr="12345"> and then the rest of the
xml..
3 - If I change to an excel file as source. How should I change the
code?

Any suggestions are appreciated. Maybe my code is not so "ruby"? Please
show me an example of how I can improve :)

Br
cristian

[code]
require 'csv'
require 'builder'

File.open("testXML.xml","w"){|f|
  builder = Builder::XmlMarkup.new(:target => f, :indent => 2)
  builder.instruct!

  csv = CSV.open('mytest.csv','rb',:headers=>true)


  builder.statusinfo("date"=>"#{Time.now}", "count" =>
"#{csv.readlines.size}")
  builder.type{#, "upgnr"=>"12345"

# Question 1: I would like to use > csv.each do |invoice|
    CSV.open('mytest.csv','rb',:headers=>true).each do |invoice|

      column = invoice[0].split(";")

      builder.status{|b|
        b.custid("#{column[1]}")
        b.invno("#{column[2]}")
        b.date("#{column[4]}")
        b.code("#{column[8]}")
        b.date2("#{column[9]}")
      }
    end
  }
}
[/code]

-- 
Posted via http://www.ruby-forum.com/.