I'm trying to parse data stored in XML format into my Windows application using C#. I'd like specific XML Nodes listed in a TreeView. When the TreeView Nodes are clicked I need corresponding XML data displayed in a different panel in the application using perhaps a DataGridView.
Currently I have the TreeView part working. But I think I might be doing it inefficiently. I'm currently just traversing each XML Node through it's ChildNodes (using foreach loops) adding XML Nodes to the TreeView when appropriate. This works, but I'm afraid it might be slow on a large file.
What I really need help on is getting the correct data to display in the DataGridView. If the XML looks like this:
Expand|Select|Wrap|Line Numbers
- <CustomerOrders>
- <Customers>
- <CustomerID>ALFKI</CustomerID>
- <Orders>
- <OrderID>10643</OrderID>
- <CustomerID>ALFKI</CustomerID>
- <OrderDate>1997-08-25T00:00:00</OrderDate>
- </Orders>
- <Orders>
- <OrderID>10692</OrderID>
- <CustomerID>ALFKI</CustomerID>
- <OrderDate>1997-10-03T00:00:00</OrderDate>
- </Orders>
- <CompanyName>Alfreds Futterkiste</CompanyName>
- </Customers>
- <Customers>
- <CustomerID>ANATR</CustomerID>
- <Orders>
- <OrderID>10308</OrderID>
- <CustomerID>ANATR</CustomerID>
- <OrderDate>1996-09-18T00:00:00</OrderDate>
- </Orders>
- <CompanyName>Ana Trujillo Emparedados y helados</CompanyName>
- </Customers>
- </CustomerOrders>
CustomerOrders
--Customers
----Orders
----Orders
--Customers
----Orders
When the user clicks on the first Customers Node, I'd like both Orders for that Customers displayed in the DataGridView. If the user clicks on on a specific Order, just that Order is displayed. If the user clicks on CustomerOrders, all Orders for all Customers will be displayed.
I'm currently trying to load the XML file into a DataSet, then get the correct data from the DataSet into a DataTable, and then bind that DataTable to the DataGridView. But I can't seem to get that to work.
I'm curious if this would be easier if I created an XML Schema to go along with it. What would an appropriate Schema look like (I'm studying them now)?
All help welcome, thanks, sorry this is so long.