Re: CSV to XML
- From: James Gray <james@xxxxxxxxxxxxxxxxxxx>
- Date: Sat, 25 Oct 2008 14:32:03 -0500
On Oct 25, 2008, at 1:41 PM, Bee Tard wrote:
Great forum, been a reader for a long time. My first post comes as a
request for some help.
I am trying to process a CSV of undetermined length (want to know
incorporate 'wc -l').
The CSV has 4 columns that I want to map to XML nodes.
I am having trouble writing each CSV line to an individual XML file
lines = 100 XML files). The first CSV element in each line would be
xml file name.
Seems pretty straight forward but I am pulling my hair out trying to
make it work. Any help would be greatly appreciated. I have googled
everywhere for it. I appreciate any help in advance!
How about something like this:
$ cat for_xml.csv
$ cat csv2xml.rb
#!/usr/bin/env ruby -wKU
FCSV.foreach(ARGV.shift, :headers => true) do |row|
File.open(row["filename"] + ".xml", "w") do |f|
# create XML data here...
$ ruby csv2xml.rb for_xml.csv
$ ls *.xml
one.xml three.xml two.xml
Hope that helps.
James Edward Gray II
- CSV to XML
- From: Bee Tard
- CSV to XML
- Prev by Date: Re: Join all text files in a folder, with a single line of Ruby code
- Next by Date: question about method call
- Previous by thread: CSV to XML
- Next by thread: question about method call