public static void Sample_ReadXml_WriteCsv_Address() { string sampleDataPath = @"..\..\Samples\"; var watch = new Stopwatch(); using (var reader = new XmlAdapter()) { reader.FileName = sampleDataPath + @"GetAddressResponse.xml"; reader.XPath = "/GetAddressResponse/GetAddressResult/result/address"; using (var writer = new CsvAdapter()) { writer.FileName = sampleDataPath + @"flatxml.csv"; watch.Start(); int lineCount = 0; reader.ReadData(30) .ForEach(x => { Console.WriteLine("Tablename=" + x.TableName + ", Count=" + x.Rows.Count); lineCount += x.Rows.Count; }) .Do(x => writer.WriteData(x)); watch.Stop(); Console.WriteLine("lineCount=" + lineCount + ", Time=" + watch.Elapsed); Console.ReadLine(); } } }
public static void Sample_Rss_Focus() { var request = HttpWebRequest.Create("http://rss.focus.de/fol/XML/rss_folnews.xml") as HttpWebRequest; if (request != null) { using (var response = request.GetResponse() as HttpWebResponse) { using (var responseStream = response.GetResponseStream()) { using (var reader = new XmlAdapter(responseStream)) { reader.XPath = "/rss/channel/item"; foreach (var table in reader.ReadData(30)) { foreach (DataRow row in table.Rows) { Console.WriteLine(row.ToDictionary <object>().ToFormattedString()); } } } } } } }
public static void Sample_ReadXml_WriteCsvs_Kunden() { string sampleDataPath = @"..\..\Samples\"; var watch = new Stopwatch(); using (var reader = new XmlAdapter()) { reader.FileName = sampleDataPath + @"kunden.xml"; reader.XPath = "/adre/kunde"; reader.ReadFormatter = new XmlToDataSetFormatter(); using (var writer = new CsvAdapter()) { writer.FileName = ""; watch.Start(); int lineCount = 0; reader.ReadData(30) .ForEach(x => { writer.FileName = sampleDataPath + x.TableName + ".csv"; Console.WriteLine("Tablename=" + x.TableName + ", Count=" + x.Rows.Count); lineCount += x.Rows.Count; }) .Do(x => writer.WriteData(x)); watch.Stop(); Console.WriteLine("lineCount=" + lineCount + ", Time=" + watch.Elapsed); Console.ReadLine(); } } }
public void Test_ReadXml_WriteCsv_Address() { using (var reader = new XmlAdapter()) { reader.FileName = Path.Combine(this.testDataPath, @"GetAddressResponse.xml"); reader.XPath = "/GetAddressResponse/GetAddressResult/result/address"; using (var writer = new CsvAdapter()) { writer.FileName = Path.Combine(this.resultPath, @"flatxml.csv"); int lineCount = 0; reader.ReadData(30) .ForEach(x => { Console.WriteLine("Tablename=" + x.TableName + ", Count=" + x.Rows.Count); lineCount += x.Rows.Count; }) .Do(x => writer.WriteData(x)); } } // check var targetlineCount = File.ReadLines(this.resultPath + @"flatxml.csv").Count(); Assert.AreEqual(3, targetlineCount); }
public void Test_ReadXml_WriteSqlite_Address() { using (var reader = new XmlAdapter()) { reader.FileName = this.testDataPath + @"GetAddressResponse.xml"; reader.XPath = "/GetAddressResponse/GetAddressResult/result/address"; using (var writer = new SqliteAdapter()) { writer.FileName = this.resultPath + @"flatxml.sqlite"; writer.CreateNewFile(); if (!writer.Connect()) { throw new Exception("No connection"); } int lineCount = 0; reader.ReadData(30) .ForEach(x => { Console.WriteLine("Tablename=" + x.TableName + ", Count=" + x.Rows.Count); lineCount += x.Rows.Count; }) .Do(x => writer.WriteData(x)); writer.Disconnect(); Assert.IsTrue(File.Exists(writer.FileName)); Assert.AreEqual(2, lineCount); } } }
public static void Sample_ReadXml_WriteSqlite_Address() { string sampleDataPath = @"..\..\Samples\"; var watch = new Stopwatch(); using (var reader = new XmlAdapter()) { reader.FileName = sampleDataPath + @"GetAddressResponse.xml"; reader.XPath = "/GetAddressResponse/GetAddressResult/result/address"; using (var writer = new SqliteAdapter()) { writer.FileName = sampleDataPath + @"flatxml.sqlite"; writer.CreateNewFile(); if (!writer.Connect()) { throw new Exception("No connection"); } watch.Start(); int lineCount = 0; reader.ReadData(30) .ForEach(x => { Console.WriteLine("Tablename=" + x.TableName + ", Count=" + x.Rows.Count); lineCount += x.Rows.Count; }) .Do(x => writer.WriteData(x)); writer.Disconnect(); watch.Stop(); Console.WriteLine("lineCount=" + lineCount + ", Time=" + watch.Elapsed); Console.ReadLine(); } } }