public ImmutableArray <Record> Records() { var reader = new XmlRecordReader(XDocument, Options); reader.ReadAll(); return(reader.Records.ToImmutableArray()); }
private void MainForm_Load(object sender, System.EventArgs e) { string fileToLoad = "../../../../../sample data/products.xml"; using (StreamReader reader = new StreamReader(fileToLoad, Encoding.UTF8)) { XmlTextBox.Text = reader.ReadToEnd(); } using (XmlRecordReader reader = new XmlRecordReader(fileToLoad, "products/product")) { reader.Columns.Add("productID", "ProductID"); reader.Columns.Add("productName", "ProductName"); reader.Columns.Add("supplierID", "SupplierID"); reader.Columns.Add("categoryID", "CategoryID"); reader.Columns.Add("quantityPerUnit", "QuantityPerUnit"); reader.Columns.Add("unitPrice", "UnitPrice"); reader.Columns.Add("unitsInStock", "UnitsInStock"); reader.Columns.Add("unitsOnOrder", "UnitsOnOrder"); reader.Columns.Add("reorderLevel", "ReorderLevel"); reader.Columns.Add("discontinued", "Discontinued"); dataGrid.DataSource = reader.ReadToEnd(); } using (MemoryStream result = new MemoryStream()) { using (XmlRecordReader reader = new XmlRecordReader(fileToLoad, "products/product")) using (CsvWriter writer = new CsvWriter(result, ',', Encoding.Default)) { reader.Columns.Add("productID", "ProductID"); reader.Columns.Add("productName", "ProductName"); reader.Columns.Add("supplierID", "SupplierID"); reader.Columns.Add("categoryID", "CategoryID"); reader.Columns.Add("quantityPerUnit", "QuantityPerUnit"); reader.Columns.Add("unitPrice", "UnitPrice"); reader.Columns.Add("unitsInStock", "UnitsInStock"); reader.Columns.Add("unitsOnOrder", "UnitsOnOrder"); reader.Columns.Add("reorderLevel", "ReorderLevel"); reader.Columns.Add("discontinued", "Discontinued"); writer.WriteAll(reader.ReadToEnd()); } using (StreamReader resultReader = new StreamReader(new MemoryStream(result.GetBuffer()))) { CsvTextBox.Text = resultReader.ReadToEnd(); } } }