Thursday, January 22, 2009

XmlCsvReader

I found a new tool yesterday that saved me from having to type up some sample XML. In preparing for a XSLT demo I wanted to use some sample data returned from a stored procedure in our database. I was able to take those results and get them into a .CSV file but needed to then get it into an XML format. The idea is the data may start out as this:

FirstName,LastName,Employer
Homer,Simpson,Springfield Nuclear Power Plant
Kermit,Frog,Muppet Theatre

but I want it to end up like this:

<People>
<Person>
<FirstName>Homer</FirstName>
<LastName>Simpson</LastName>
<Employer>Springfield Nuclear Power Plant</Employer>
</Person>
<Person>
<FirstName>Kermit</FirstName>
<LastName>Frog</LastName>
<Employer>Muppet Theatre</Employer>
</Person>
</People>


A quick search on Google brought me to this post about a tool called XmlCsvReader. It seemed to be just what I needed, but the link to download the tool was dead (still pointing to GotDotNet.com, which has been defunct for a while). Armed with the name of the project, though, I Googled again and found another post about it with a download that worked (three cheers to Andrew for not having a dead end!).

Syntax is easy and the only snags I hit were the result of QueryAnalyzer, excuse me, SQL Server Management Studio 2005, not being able to save sproc results to a CSV file correctly. I had to type in my column headers and wrap text values in double quotes if they had commas.