WriteXML / WriteXMLSchema

Posted on 2008-11-13
Last Modified: 2013-12-17
I want to know:

(1) What is the difference between:

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


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.
Question by:rpkhare
    LVL 13

    Accepted Solution

    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();
        // Rewind the memory stream.
        xmlStream.Position = 0;
        DataTable newTable = new DataTable();

    Open in new window

    LVL 8

    Author Comment

    When I use "WriteXML", what if the XSD file already contains old data? Is it cleared on each fill?
    LVL 13

    Expert Comment

    xsd will have schema..there will no data. are you changing schema on every write..if not it should be ok.
    LVL 8

    Author Comment

    What if I write only:


    and don't provide the XML write mode?
    LVL 96

    Assisted Solution

    by:Bob Learned
    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

    LVL 8

    Author Closing Comment


    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
    For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK ( for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now