CHAPTER 22 ADO.NET PART II: THE DISCONNECTED LAYER
document. In addition, DataSets and DataTables both support WriteXmlSchema() and ReadXmlSchema()
for saving or loading an *.xsd file.
To test this out for yourself, update your Main() method to call the following helper function (notice
that you pass a DataSet as the sole parameter):
static void SaveAndLoadAsXml(DataSet carsInventoryDS)
{
// Save this DataSet as XML.
carsInventoryDS.WriteXml("carsDataSet.xml");
carsInventoryDS.WriteXmlSchema("carsDataSet.xsd");
// Clear out DataSet.
carsInventoryDS.Clear();
}
// Load DataSet from XML file.
carsInventoryDS.ReadXml("carsDataSet.xml");
If you open the carsDataSet.xml file (which you will find under the \bin\Debug folder of your
project), you will find that each column in the table has been encoded as an XML element.
0BMWBlackHamlet1SaabRedSea Breeze
If you were to double-click on the generated *.xsd file (also found under your \bin\Debug folder)
within Visual Studio, you will open the IDE’s XML schema editor (see Figure 22-3).
875