O'Reilly logo

Wicked Cool Ruby Scripts by Steve Pugh

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

CSV to XML

CSV to XML

csvToXML.rb

If you want to populate information to the Web, Extensible Markup Language (XML) is a good format to use. The reason XML is so cool is because the format enables different systems to share data using a common format that the developer can design. This script will take the information stored in a CSV file and, instead of just outputting the comments to the user's terminal, will produce an XML file.

The Code

 require 'faster_csv'

 print "CSV file to read: " infile = gets.strip print "What do you want to call each element: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required