« Larry @ Zdnet | Main | The myth of LINQ (simplest sample for ADO.NET Entity Data Model) »

Write Table content from Database to XML file


I found the easiest way to write a table or even tables from database to XML file is in.NET languages. To do this in Java you might probably need to include not only one but few proprietary library or open source jar file.

 

To do this in C#, one of the .NET languages, there is no additional reference need to be added to the project. Only using System.Data is needed because of the Dataset.

 

The code segment that writes dataset to XML file as follow (the code segment is from MSDN library):

 

    static void WriteXmlToFile(DataSet thisDataSet)

    {

      if (thisDataSet == null) { return; }

 

      // Create a file name to write to.

      string filename = "XmlDoc.xml";

 

      // Create the FileStream to write with.

      System.IO.FileStream stream = new System.IO.FileStream

          (filename, System.IO.FileMode.Create);

 

      // Write to the file with the WriteXml method.

      thisDataSet.WriteXml(stream);

}

 

The complete code to extract the data from employee table of HR schema to XML from is in http://skydrive.live.com. The sample file name is ConsoleDatasettoXML .zip. My MSN ID is chanmmn@hotmail.com.

Comments (3)

Erik Ykema:

You may also enjoy native SQL and/or native PL/SQL (see e.g. http://www.orafaq.com/wiki/DBMS_XMLGEN for a sample of the dbms_xmlgen package), though I must admit that this C# sample has very few lines of code.

You might be surprised that it can be even easier...

Althouth a "select from relational table" is not in the example, it would be just be an easy adjustment.

Have a look at: http://www.liberidu.com/blog/?p=365

thank u r information

it very useful

u r blog Is very nice

Post a comment

About This Entry

This page contains a single entry from the blog posted on October 12, 2008 12:45 AM.

The previous post in this blog was Larry @ Zdnet.

The next post in this blog is The myth of LINQ (simplest sample for ADO.NET Entity Data Model).

Many more can be found on the main index page or by looking through the archives.

Top Tags

Powered by
Movable Type and Oracle