Map XML into Strongly-Typed Dataset



    I am looking for more information about taking an XML file and importing it into a strongly-typed dataset.  Things like how do I deal with attributes and map those to the dataset columns, etc...  Any help would be appreciated.  Thanks.



    Thursday, October 23, 2008 12:13 PM

All replies

  • You can read about the DataColumn.ColumnMapping property which allows columns to be mapped as attributes.


    Thursday, October 23, 2008 4:10 PM
  • Mark,


    I appreciate the response, but what I am looking for is where to find more information about the whole process.  I want to be able to import XML into a strongly-typed dataset and use that dataset in the VS 2008 IDE.  Thanks.


    Monday, October 27, 2008 2:06 PM

    Here is a link that discusses XML and Dataset and how they are related.



    I think the simpliest way to get Xml into the DataSet is to add Data into a dataset directly and then simply call WriteXml on the data set and it will produce an Xml file that can be read back in using ReadXml.


    Now if you have a verify specific formatted XML and you want to read this into Dataset I think there are two options. If the format coincides with closely with the format that dataset produces with WriteXml you can likely use the column mapping structures example that Mark gave earlier in the thread to convert this data into a dataset.


    If the format of your data doesn't quite match the format that DataSet will read then I think you will be forced to hand code a solution. You can use a XmlDocument, or an XmlReader, or XLinq, and parse out the values and then simply add them into dataset. You would have to have a DataTable create with the columns it would have. Then you can call table.NewRow(). You would fill out all the values of columns in the row and then you can do tables.Rows.Add(row) to add this into the table. This process would have to be followed for each set of data that is table like within your xml.


    If you would like more help on the specifics feel free to post a sample xml file that contains what you are trying to import and then Mark Ashton or I can help futher on the specifics.



    Chris Robinson

    Program Manager - Dataset

    Monday, October 27, 2008 5:26 PM
  • Chris,


    Thanks for the reply and I will read through the article.  I just have a few additional questions if you don't mind.  First, what is the best way to build a dataset from an XML file in the VS IDE?  It would be nice to build the dataset from an XML file and then use it for databinding in the IDE.  Currently,  I use the XML to Schema tool from the VB Powerpacks.  Then I open the file using the dataset designer and then save it.  From there I need to set the Custom Tool property to MSDatasetGenerator and run it.  Second, this allows me to then use the dataset in the designer, but when I load the xml file into the dataset using readxml, no rows are loaded into the dataset.  So, what is then the best way to map this data?  Thanks for your time.




    Tuesday, October 28, 2008 3:58 PM