C# datatable to XML

Mercypoint

Weaksauce
Joined
Oct 22, 2005
Messages
74
I'm wondering if there is an easier way then what I am doing right now.

Currently, I have a XSD and a database table. The XSD is pretty nested but the table is very flat. I need to have a way to "map" the fields of the database table so I can easily export the the rows of data into XML.

I have tried xsd.exe to create a strongly-typed dataset but the XSD is too complex that the SDK tool can't handle some of the nesting. So I am forced to write the xml via stringbuilder or xmltextwriter.

There has to be a better way to do this then to recursive through all the records.

any ideas?
 
I saw the term "DataTable" in the post's title, and first thought of the ReadXML() and WriteXML() methods of a DataSet object. So if you have an actual DataTable object, then load it as the first table in a DataSet object, and use those methods as needed.

If not, then please clarify.
 
I use 'datatable' because the database view that is provided to me is just that, one table. In reality, the data source is coming from many many different databases.

Because of the complexity of the XSD, I can not simply do a writeXML. From my understanding, writeXML will simply write a XML file that has the exact structure as the view. Unfortunately, the XSD is heavy in "complexType" and the view is very flat so some mapping is required. I guess it is a lot like converting an Excel (flat) dataset to Object orientated.
 
Back
Top