I have an XML Data Source which contains a list of key/value pairs. I'm looking for a simple way to load the same data into an array or some other data structure so that I can easily look up the data. I can bind it to a GridView with a couple of clicks but I'm failing to find a straightforward way to load it into something that isn't a UI Control.
My data source looks like:
<SiteMap>
<Sections>
<Section Folder="TradeVolumes" TabIndex="1" />
<Section Folder="TradeBreaks" TabIndex="2" />
</Sections>
</SiteMap>
I'm wanting to load key value pairs (Folder, TabIndex)
What is the best way to load the data?
Use XmlSerializer and deserialize it into your own type. Then use it as datasource Quite straightforward example can be found here - http://msdn.microsoft.com/en-us/library/ms950721.aspx
You can do something like this, The code below is based on the on the xml you have included in your questions.
Using Linq to XML :
You get a dictionary, which is basically a collection of key/value pairs
Load it into a DataSet with the function
with your data you will have a dataset with 2 tables: