This project contains a library that you can use to convert data stored in XML to Comma Seperated Values. There is also a client application included. The project is built with C#4.0. Currently there is one algorithm for the conversion implemented (using
strategy pattern), namely the XmlToCsvUsingDataSet implementation. This conversion algorithm will work with any XML that is the result of an ADO.Net DataSet.SaveAsXml action. However, I believe the converter is should work with any tabular shaped XML data.
Other implementations of the same conversion can easily be added by implementing for example an XmlToCsvUsingLinq strategy. In fact, the code skeleton for a XmlToCsvUsingLinq stretegy is included for future implementation, but be aware that at the moment it
will throw a NotImplementedException.
For large datasets, the current XmlToCsvUsingDataSet works pretty fast (it parses and saves 28 enities/tables to a CSV file from a 133 mb xml source file in just over 10 seconds).
Code usage example:
public void ConvertUsingDataSet()
var converter = new XmlToCsvUsingDataSet(@"C:\Payslip.xml");
var context = new XmlToCsvContext(converter);
foreach (string xmlTableName in context.Strategy.TableNameCollection)
context.Execute(xmlTableName, @"C:\" + xmlTableName + ".csv", Encoding.Unicode);
Example execution of the command line tool from the command prompt:
XmlToCsv.Console.exe -xml c:\payslip.xml -dir c:\convertedcsvfiles
To get the command line tool help screen: