will u please explain breafly
how should be the xml schema.
for the following .xml file...
<?xml version="1.0" encoding="utf-8" ?>
<countries>
<country name="india">
<capital>Delhi</capital>
</country>
<country name="SriLanka">
<capital>Colombo</capital>
</country>
<country name="nepal">
<capital>khatmandu</capital>
</country>
</countries>
thank you
You need to create xsd file for the xml file that you have.
in VS.NET environment, open the XML file and right click on any part of the data. You can see "Create Schema" Option there. Click on that and VS will create an xsd file for you. Only thing you need to do is change the second line of your xml file as
<countries xmlns="http://tempuri.org/testFile1.xsd">
Following method can be used for retriving a Dataset from an XML file
private DataSet getXmlDataSet(string xmlFileName,string xmlSchemaFile)
{
XmlDataDocument xmlFile = new XmlDataDocument();
DataSet ds = new DataSet();
try
{
xmlFile.DataSet.ReadXmlSchema(xmlSchemaFile);
XmlTextReader TrainReader = new XmlTextReader(xmlFileName);
TrainReader.MoveToContent();
xmlFile.Load(TrainReader);
ds = xmlFile.DataSet;
}
catch (Exception e)
{
ds.Dispose();
MessageBox.Show(this,e.Message,"Error");
}
return ds;
}
Let me know if you have any problem.