[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1636
  • Last Modified:

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.
0
rpkhare
Asked:
rpkhare
  • 3
  • 2
2 Solutions
 
SameerJagdaleCommented:
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
rpkhareAuthor Commented:
What if I write only:

DataSet1.Tables[0].WriteXML(XSDName)

and don't provide the XML write mode?
0
 
Bob LearnedCommented:
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

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now