Generating XSD file dynamically.

A

archana

Hi all,

Can anyone tell me how to generate xsd file dynamically for datatable.
And then how to create datatable from that dynamically generated xsd
file.

I want to generate datatable from this dynamically generated xsd file.

Can anyone tell how to do this? means how to generate xsd file
dynamically with for some column default value. and then how to
generate datatable from that xsd file.

any help will be truely appreciated.
 
C

Claire

Hi Archana,
This is how I create xsd from visual studio 2003 using ADO. Ive not tried to
create table from xsd in reverse so cant help u there.

Pseudo Code

In form
DataSet ds = databasehandler.CreateMyDataset();

In databasehandler
private DataSet CreateMyDataset()
{
string sql = "SELECT SOME RECORDS"
IDbConnection Connection = GetConnection() (GetConnection opens database
with connection strings etc)
DataSet result = new DataSet();
IDbDataAdapter Adapter = new SqlDataAdapter();
IDbCommand command = Connection.CreateCommand();
command.CommandText = sql;
Adapter.SelectCommand.= command;
Adapter.Fill(result);
return result;
}

form now has a filled dataset
databasehandler.WriteXSDSchema(ds,"MyDataset.xml");

Back to databasehandler for writing schema. Make sure that xsd.exe is in the
same directory as your main application or is in %path%
Following creates xsd file from dataset
public void WriteXSDSchema(DataSet ds, string xmlfilename)
{
#region WriteXSDSchema
// Write the schema to xml file
ds.WriteXmlSchema(xmlfilename);
try
{
// convert xml to xsd. xsd.exe should be in output path
if (File.Exists("xsd.exe"))
{
Process p = Process.Start("xsd.exe",xmlfilename);
if (p != null)
{
// Wait for it to exit then delete the xml file which isnt needed
p.WaitForExit(2000);
File.Delete(xmlfilename);
}
}
else
MessageBox.Show("xsd.exe is missing from application output path. This
function can not continue");
}
catch(Exception e)
{
MessageBox.Show(e.Message);
}
#endregion
}// function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top