This article was written on October 07, 2010 by CyberNet.
The other day I was looking for a way to take a large CSV file worth of data and convert it into corresponding XML nodes. I wanted the first line of the CSV file to serve as each individual node name so that it could be easily parsed, and most of all I wanted an online solution because I knew I shouldn’t need a full-fledged application to do something this mundane.
After a few quick searches I came across Mr. Data Converter. It’s an awesome utility that lets you paste in any CSV (comma separated values) or tab-delimited data, and it will turn it into one of nine different formats. A full list of compatible formats are below, and notably include HTML, XML, and JSON.
To put the data converter to the test I went ahead and created a very brief CSV file that I could pass through the service to examine what the output looks like. Here’s the CSV content that I started with:
Name,Class,Age,Grade
Jason,Math,14,A
Beth,English,16,B+
Anne,Math,15,A+
And this is the resulting output for all of the supported types:
- Actionscript
[{name:"Jason",class:"Math",age:"14",grade:"A"},
{name:"Beth",class:"English",age:"16",grade:"B+"},
{name:"Anne",class:"Math",age:"15",grade:"A+"}]; - ASP/VBScript
Dim myArray(3,2)
myArray(0,0) = "Jason"
myArray(1,0) = "Math"
myArray(2,0) = "14"
myArray(3,0) = "A"
myArray(0,1) = "Beth"
myArray(1,1) = "English"
myArray(2,1) = "16"
myArray(3,1) = "B+"
myArray(0,2) = "Anne"
myArray(1,2) = "Math"
myArray(2,2) = "15"
myArray(3,2) = "A+" - HTML
<table>
<thead>
<tr>
<th class="name-cell">name</th>
<th class="class-cell">class</th>
<th class="age-cell">age</th>
<th class="grade-cell">grade</th>
</tr>
</thead>
<tbody>
<tr class="firstRow">
<td class="name-cell">Jason</td>
<td class="class-cell">Math</td>
<td class="age-cell">14</td>
<td class="grade-cell">A</td>
</tr>
<tr>
<td class="name-cell">Beth</td>
<td class="class-cell">English</td>
<td class="age-cell">16</td>
<td class="grade-cell">B+</td>
</tr>
<tr class="lastRow">
<td class="name-cell">Anne</td>
<td class="class-cell">Math</td>
<td class="age-cell">15</td>
<td class="grade-cell">A+</td>
</tr>
</tbody>
</table> - JSON – Properties
[{"name":"Jason","class":"Math","age":"14","grade":"A"},
{"name":"Beth","class":"English","age":"16","grade":"B+"},
{"name":"Anne","class":"Math","age":"15","grade":"A+"}]; - JSON – Array
[["Jason","Math","14","A"],
["Beth","English","16","B+"],
["Anne","Math","15","A+"]]; - PHP
array(
array("name"=>"Jason","class"=>"Math","age"=>"14","grade"=>"A"),
array("name"=>"Beth","class"=>"English","age"=>"16","grade"=>"B+"),
array("name"=>"Anne","class"=>"Math","age"=>"15","grade"=>"A+")
); - Ruby
[{"name"=>"Jason","class"=>"Math","age"=>"14","grade"=>"A"},
{"name"=>"Beth","class"=>"English","age"=>"16","grade"=>"B+"},
{"name"=>"Anne","class"=>"Math","age"=>"15","grade"=>"A+"}]; - XML – Properties
<?xml version="1.0" encoding="UTF-8"?>
<rows>
<row name="Jason" class="Math" age="14" grade="A" ></row>
<row name="Beth" class="English" age="16" grade="B+" ></row>
<row name="Anne" class="Math" age="15" grade="A+" ></row>
</rows> - XML – Nodes
<?xml version="1.0" encoding="UTF-8"?>
<rows>
<row>
<name>Jason</name>
<class>Math</class>
<age>14</age>
<grade>A</grade>
</row>
<row>
<name>Beth</name>
<class>English</class>
<age>16</age>
<grade>B+</grade>
</row>
<row>
<name>Anne</name>
<class>Math</class>
<age>15</age>
<grade>A+</grade>
</row>
</rows>
Pretty awesome, huh? This also makes a handy programming tool since it is able to create arrays for Ruby, PHP, ASP, and even ActionScript. Oh, and if you’re using Microsoft Excel you can just highlight the cells you want to use, copy them, and they will be pasted into the data converter using a format it understands. With that in mind you can actually use Excel functions to help generate random testing data, and then use the convert to get it into the format you need.
Copyright © 2010 CyberNet | CyberNet Forum | Learn Firefox
Related Posts:
- Convert Firefox Bookmarks & Feeds To IE7Super Is the Ultimate Video ConverterConvert Your Favorite Firefox Extensions to Work with FlockBulk Convert VideosDel.icio.us Offers a Tagometer Badge for your Site