WriteXML / WriteXMLSchema

I want to know:

(1) What is the difference between:

DataSet.Tables[0].WriteXML("File.XSD", XMLWriteMode.Schema)

and

DataSet.Tables[0].WriteXML Schema

(2) I already have .XSD files created with the above methods. But I am using above methods each time when the application is run. This is slowing reports. I therefore want to fill the existing XSD file but it should not create XML Schema again.
LVL 8
rpkhareAsked:
Who is Participating?
 
SameerJagdaleConnect With a Mentor Commented:
there is a big difference between the two:

Use the WriteXmlSchema method to write the schema for a DataTable to an XML document. The schema includes table, relation, and constraint definitions.
Use the WriteXml method to write the data to an XML document.
check out readxmlschema method to read the schema definition..check out the sample code:

// Write the schema to XML in a memory stream.
    System.IO.MemoryStream xmlStream = new System.IO.MemoryStream();
    table.WriteXmlSchema(xmlStream);
 
    // Rewind the memory stream.
    xmlStream.Position = 0;
 
    DataTable newTable = new DataTable();
    newTable.ReadXmlSchema(xmlStream);

Open in new window

0
 
rpkhareAuthor Commented:
When I use "WriteXML", what if the XSD file already contains old data? Is it cleared on each fill?
0
 
SameerJagdaleCommented:
xsd will have schema..there will no data. are you changing schema on every write..if not it should be ok.
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
rpkhareAuthor Commented:
What if I write only:

DataSet1.Tables[0].WriteXML(XSDName)

and don't provide the XML write mode?
0
 
Bob LearnedConnect With a Mentor Commented:
It may help to look at what happens in the .NET framework when you call the WriteXml with a file name:


public void WriteXml(string fileName)
{
    this.WriteXml(fileName, XmlWriteMode.IgnoreSchema, false);
}

Open in new window

0
 
rpkhareAuthor Commented:
Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.