Wednesday, August 12, 2009

XML to DataTable and viceversa

If you want to get an XML data to Dataset you need following things

  1. .xsd Xml schema file
  2. .xml XML file



using System.Xml;
string tableName = "tableName";
string fileName = "fileName ";
expected.TableName = tableName;
expected.ReadXmlSchema("\\" + fileName + ".xsd");
expected.ReadXml("\\" + fileName + ".xml");


This wil create a XML and XSD file for DataTable values which is fetched from Database using storeproc.



string tableName = "GetUsersBySalesOrg";
DataTable expected = new DataTable(); //Initialize to an appropriate value
expected = className.StoreProcReturnsDatatable(val1, val2);
expected.TableName = tableName;
expected.WriteXml("\\"+tableName+".xml");
expected.WriteXmlSchema("\\" + tableName + ".xsd");

No comments:

Post a Comment