zimcoder Level: VB Lord

 Registered: 27-10-2003 Posts: 225
|
Re: how to generate xml schema automatically from any xml file ?
You can use the dataset methods to read and write xml schema
first let us read an xml file into our dataset
private void ReadSchemaFromFile(){
// Create the DataSet to read the schema into.
DataSet thisDataSet = new DataSet();
// Set the file path and name. Modify this for your purposes.
string filename="mySchema.xml";
// Invoke the ReadXmlSchema method with the file name.
thisDataSet.ReadXmlSchema(filename);
// more code coming here
} |
Once you have the schema for the dataset you can write it out as a schema file
private void ReadSchemaFromFile(){
// Create the DataSet to read the schema into.
DataSet thisDataSet = new DataSet();
// Set the file path and name. Modify this for your purposes.
string filename="mySchema.xml";
// Invoke the ReadXmlSchema method with the file name.
thisDataSet.ReadXmlSchema(filename);
// Display the DataSet schema as XML.
Console.WriteLine( ds.GetXmlSchema() );
} |
this should return a string that is an XSD file
____________________________
BrainBench ADO.NET and ASP.NET Certified Developer
 
|