Can I load an XPath result XmlNodeList into a Dataset/DataGrid?
-
I'm writing a C# Windows/.Net 2.0 app which will take a large XML document as an initial input. My form has 4 basic controls: 3 comboboxes (Country, State, and City) for filtering the XML data and a DataGrid to display the results. The XML doc has this format: I have no problem using XPath queries to extract the values to populate the Country, State, and City comboboxes; each selection drives the data in the subsequent combobox. Upon selection in the City combobox, I can query for a resulting set of 'locations'. My problem is how to stuff this XmlNodeList into a DataSet which I can then use with my DataGrid. I have no problem reading an entire document into a DataSet DataSet ds = new DataSet(); ds.ReadXml("Test.Search.xml"); but have no idea how to stuff an XmlNodeList into one. Thanks. Jack80918
-
I'm writing a C# Windows/.Net 2.0 app which will take a large XML document as an initial input. My form has 4 basic controls: 3 comboboxes (Country, State, and City) for filtering the XML data and a DataGrid to display the results. The XML doc has this format: I have no problem using XPath queries to extract the values to populate the Country, State, and City comboboxes; each selection drives the data in the subsequent combobox. Upon selection in the City combobox, I can query for a resulting set of 'locations'. My problem is how to stuff this XmlNodeList into a DataSet which I can then use with my DataGrid. I have no problem reading an entire document into a DataSet DataSet ds = new DataSet(); ds.ReadXml("Test.Search.xml"); but have no idea how to stuff an XmlNodeList into one. Thanks. Jack80918
As you probably already know, an
XmlNodeList
is really a collectionXmlNode
s. You have mentioned you can read an XML document directly into aDataSet
. So, I can give you a some suggestions. 1. You can create anXmlDocument
populating it withXmlNode
s cloned from theXmlNodeList
. 2. You can create anXmlDocument
using XSLT with the same criteria you used to create theXmlNodeList
. 3. You can create aDataTable
(orDataTable
s) that corresponds to yourXmlNodeList
and extract data from yourXmlNode
s into the appropriate rows and columns. There are certainly other ways of doing this. So, search the web for ideas or just be creative."We make a living by what we get, we make a life by what we give." --Winston Churchill