Exemplo n.º 1
0
        public static void ConvertTables(String xmlInputFilePath, String outputDirectory)
        {
            var converter = new XmlToCsvUsingDataSet(xmlInputFilePath);
            var context = new XmlToCsvContext(converter);

            foreach (string xmlTableName in context.Strategy.TableNameCollection)
            {
                context.Execute(xmlTableName, outputDirectory + "/" + xmlTableName + ".csv", Encoding.Default);
            }
        }
Exemplo n.º 2
0
 public void LinqImplementationTest()
 {
     const string path = @"data.xml";
     var converter = new XmlToCsvUsingLinq(path);
     var context = new XmlToCsvContext(converter);
     Assert.AreEqual(1, context.Strategy.TableNameCollection.Count);
     foreach (string xmlTableName in context.Strategy.TableNameCollection)
     {
         context.Execute(xmlTableName, @"dataLinq_" + xmlTableName + ".csv", Encoding.Default);
     }
 }
Exemplo n.º 3
0
 public void CanReadAttributeTest()
 {
     const string path = @"DataWithAttributes.xml";
     var converter = new XmlToCsvUsingDataSet(path);
     var context = new XmlToCsvContext(converter);
     Assert.AreEqual(2, context.Strategy.TableNameCollection.Count);
     foreach (string xmlTableName in context.Strategy.TableNameCollection)
     {
         context.Execute(xmlTableName, @"dataDataSet_" + xmlTableName + ".csv", Encoding.Default);
     }
 }
Exemplo n.º 4
0
        public void DuplicateNameRenamedTest()
        {
            const string path = @"ErrorDuplicateName.xml";
            var converter = new XmlToCsvUsingDataSet(path, true);
            var context = new XmlToCsvContext(converter);
            Assert.AreEqual(2, context.Strategy.TableNameCollection.Count);

            foreach (string xmlTableName in context.Strategy.TableNameCollection)
            {
                context.Execute(xmlTableName, @"ErrorDuplicateName_" + xmlTableName + ".csv", Encoding.Default);
            }
        }
Exemplo n.º 5
0
        /// <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);
            }
        }