private void SaveFileDialog1FileOk(object sender, CancelEventArgs e) { try { _xmlToCsvContext.Execute(@lsbTables.SelectedItem.ToString(), @saveFileDialog1.FileName, ((KeyValuePair <string, Encoding>)ddlEncoding.SelectedItem).Value); txbLog.Text += @"Saving '" + lsbTables.SelectedItem + @"' to CSV completed." + Environment.NewLine; } catch (NullReferenceException) { MessageBox.Show(this, @"No table was selected. Please select a table.", @"No table selected error.", MessageBoxButtons.OK, MessageBoxIcon.Error); txbLog.Text += @"No table was selected. Please select a table." + Environment.NewLine; } }
public void DataSetImplementationTest() { const string path = @"TestData/data.xml"; var context = new XmlToCsvContext(new XmlToCsvUsingDataSet(path)); Assert.That(context.Strategy.TableNameCollection.Count, Is.EqualTo(1)); foreach (var xmlTableName in context.Strategy.TableNameCollection) { context.Execute(xmlTableName, @"dataDataSet_" + xmlTableName + ".csv", Encoding.Default); } }
public void DuplicateNameRenamedTest() { const string path = @"TestData/ErrorDuplicateName.xml"; var context = new XmlToCsvContext(new XmlToCsvUsingDataSet(path, true)); Assert.AreEqual(2, context.Strategy.TableNameCollection.Count); foreach (var xmlTableName in context.Strategy.TableNameCollection) { context.Execute(xmlTableName, @"ErrorDuplicateName_" + xmlTableName + ".csv", Encoding.Default); } }
public void DoubleQuoteEscapeTest() { const string path = @"TestData/DoubleQuoteEscape.xml"; var context = new XmlToCsvContext(new XmlToCsvUsingDataSet(path)); Assert.That(context.Strategy.TableNameCollection.Count, Is.EqualTo(1)); foreach (var xmlTableName in context.Strategy.TableNameCollection) { context.Execute(xmlTableName, string.Format(@"TestData/dataDataSet_{0}.csv", xmlTableName), Encoding.Default); } }
/// <summary> /// XML to CSV Command Line Converter. User as follows: XmlToCsv.Console.exe -xml C:\payslip.xml -dir C:\my_output /// </summary> /// <param name="args">First parameter selects the XML file, second parameter specifies the output directory.</param> static void Main(string[] args) { //Command line parsing library from http://cmdline.codeplex.com/ var cmd = new ConsoleCmdLine(); var xmlInputFilePath = new CmdLineString("xml", true, "XML file to convert."); var outputDirectory = new CmdLineString("dir", true, "Directory to save the CSV result to."); cmd.RegisterParameter(xmlInputFilePath); cmd.RegisterParameter(outputDirectory); cmd.Parse(args); var converter = new XmlToCsvUsingDataSet(xmlInputFilePath.Value); var context = new XmlToCsvContext(converter); foreach (string xmlTableName in context.Strategy.TableNameCollection) { context.Execute(xmlTableName, outputDirectory.Value + @"\" + xmlTableName + ".csv", Encoding.Unicode); } }