Loosing XML Schema when writing DataSet to XML

  • Thread starter Thread starter ertanasan1
  • Start date Start date
E

ertanasan1

Hi,

//Returns a new dataset with tree datatables.
dsTemp.ReadXmlSchema(@"C:\mysch.xsd");

//Add a row to data table 0
DataRow dr = dsTemp.Tables[0].NewRow();
dr["field1"] = "value1";
dsTemp.Tables[0].Rows.Add(dr);

//write dataset to xml
System.IO.StringWriter stream = new System.IO.StringWriter();
dsTemp.WriteXml(stream);
string xmlTemp = stream.ToString();

When writing to xml, it looses schema information. The output xml is
not competible with mysch.xsd which has been read at first.

What would be the reason?

Thanks.

Ertan
 
Ertan,

Have you tried the overload of WriteXml that takes a value from the
XmlWriteMode enumeration? You would want to pass the WriteSchema value to
the method.

Hope this helps.
 
Nick,

WriteSchema enum value forces WriteXml method write only the schema
information, not the data.

Thanks anyway.

Nicholas Paldino [.NET/C# MVP] yazdi:
Ertan,

Have you tried the overload of WriteXml that takes a value from the
XmlWriteMode enumeration? You would want to pass the WriteSchema value to
the method.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Hi,

//Returns a new dataset with tree datatables.
dsTemp.ReadXmlSchema(@"C:\mysch.xsd");

//Add a row to data table 0
DataRow dr = dsTemp.Tables[0].NewRow();
dr["field1"] = "value1";
dsTemp.Tables[0].Rows.Add(dr);

//write dataset to xml
System.IO.StringWriter stream = new System.IO.StringWriter();
dsTemp.WriteXml(stream);
string xmlTemp = stream.ToString();

When writing to xml, it looses schema information. The output xml is
not competible with mysch.xsd which has been read at first.

What would be the reason?

Thanks.

Ertan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top