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)
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.
Posted by Erik Ykema | October 12, 2008 2:16 AM
Posted on October 12, 2008 02:16
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
Posted by Marco Gralike | October 12, 2008 7:00 AM
Posted on October 12, 2008 07:00
thank u r information
it very useful
u r blog Is very nice
Posted by Matthew | October 15, 2008 7:07 PM
Posted on October 15, 2008 19:07