By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,932 Members | 1,474 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,932 IT Pros & Developers. It's quick & easy.

Loosing schema information while converting DataSet to XML

P: n/a
Hello,

I have a Client/Server system based on a single generic communication method
using XML (as done in MS Project-Server or SharePoint-WebServices).

To transfer DataSets I'am using XmlDataDocument.
This works fine.
However the created XmlDataDocument does not contain schema information,
i.e. the datatypes of the columns in the dataset-tables are lost.

Is there any way to include the shema info?

(I cannot use dataSet.WriteXml because I don't need a file or stream, I need
a XmlDocument!)

Thank you
Wolfgang
Code fragment:
// Create dataset or get it from database
DataSet dataSet = GetDataSet();

// Test: Write to file, including schema information
dataSet.WriteXml("C:\\test1.xml", XmlWriteMode.WriteSchema);

// Create XML document from dataset, does obviously NOT include schema
information!
XmlDataDocument xDoc = new XmlDataDocument(dataSet);

// Normally the XmlDocument will be returned here
// return xDoc;

// Test: Write to file: has NO schema information
xDoc.Save("C:\\test2.xml");
Nov 12 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi Wolfgang,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to load the schema information
into a XmlDataDocument and pass it through an xml web service. If there is
any misunderstanding, please feel free to let me know.

As far as I know, the XmlDataDocument doesn't load the schema information
by default. Since you don't want to write to any file, we can write it to a
string using a StringWriter. Here is an example:

System.Text.StringBuilder sb = new System.Text.StringBuilder();
this.dataSet12.WriteXml(new System.IO.StringWriter(sb),
XmlWriteMode.WriteSchema);
XmlDataDocument doc = new XmlDataDocument();
doc.LoadXml(sb.ToString());
doc.Save(@"c:\emp1.xml");

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 12 '05 #2

P: n/a
Hi Kevin,

thank you very much.
You get the solution!
Now everything works like expected.

Wolfgang
Nov 12 '05 #3

P: n/a
You're welcome.

Thanks for sharing your experience with all the people here. If you have
any questions, please feel free to post them in the community.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 12 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.