public void DataTable() { Layout layout = new Layout("Test Layout", "/Library", new List <LayoutNode>()); LayoutDataTable layoutdataTable = new LayoutDataTable("Book List", "Book", new List <LayoutDataTable.Column>()); layoutdataTable.Columns.Add(new LayoutDataTable.Column("The Author", "Author")); layoutdataTable.Columns.Add(new LayoutDataTable.Column("The Title", "Title")); List <LayoutDataTable> dataTables = new List <LayoutDataTable>(); dataTables.Add(layoutdataTable); LayoutNode node = new LayoutNode("Books", "/Library/Books", true, null, new List <LayoutNode>(), new List <LayoutValue>(), dataTables); layout.Nodes.Add(node); ModelParser parser = new ModelParser(layout); XmlModel model = parser.parseXmlString(XML_INPUT); Assert.AreEqual(1, model.Nodes.Count); Assert.AreEqual(1, model.Nodes[0].DataTables.Count); XmlModelDataTable dataTable = model.Nodes[0].DataTables[0]; Assert.AreEqual("Book List", dataTable.Title); Assert.AreEqual(3, dataTable.Records.Count); Assert.AreEqual("Bram Stoker", dataTable.Records[0]["The Author"]); Assert.AreEqual("Dracula", dataTable.Records[0]["The Title"]); Assert.AreEqual("Miguel de Cervantes", dataTable.Records[1]["The Author"]); Assert.AreEqual("Dom Quixote", dataTable.Records[1]["The Title"]); Assert.AreEqual("George Orwell", dataTable.Records[2]["The Author"]); Assert.AreEqual("1984", dataTable.Records[2]["The Title"]); }
private List <Dictionary <string, string> > extractDataTableRecords(XmlNode xmlNode, LayoutDataTable layoutdataTable) { List <Dictionary <string, string> > records = new List <Dictionary <string, string> > (); foreach (XmlNode xmlRecord in xmlNode.SelectNodes(layoutdataTable.RecordXPath)) { Dictionary <string, string> record = new Dictionary <string, string> (); foreach (LayoutDataTable.Column layoutColumn in layoutdataTable.Columns) { XmlNode valueNode = xmlRecord.SelectSingleNode(layoutColumn.ValueXPath); if (valueNode == null) { record.Add(layoutColumn.Name, "#ERR#"); } else { record.Add(layoutColumn.Name, valueNode.Value ?? valueNode.InnerText); } } records.Add(record); } return(records); }