Writing and Reading XML Using a DataSet Object XML is a convenient format for moving information around. You can write out the contents of the DataTable objects contained in a DataSet to an XML file using the WriteXml() method | Writing and Reading XML Using a DataSet Object XML is a convenient format for moving information around. You can write out the contents of the DataTable objects contained in a DataSet to an XML file using the WriteXml method. The XML file written by this method contains the DataTable column names and values. You can write out the schema of a DataSet object to an XML file using the WriteXmlSchema method. The XML file written by this method contains the structure of the DataTable objects contained in the DataSet. You can also get the XML in a DataSet using the GetXml method which returns the XML in a string. You can read the contents of the DataTable objects in an XML file into a DataSet using the ReadXml method. You can also read the schema contained in an XML file using the ReadXmlSchema method. Note SQL Server also contains extensive built-in XML functionality which you ll learn about in Chapter 16 Using SQL Server s XML Support. Using the WriteXml Method Let s say you have a DataSet object named myDataSet. Assume that myDataSet has a DataTable that contains the CustomerID CompanyName ContactName and Address columns for the top two rows from the Customers table. The following code shows this SqlCommand mySqlCommand SELECT TOP 2 CustomerID CompanyName ContactName Address FROM Customers ORDER BY CustomerID SqlDataAdapter mySqlDataAdapter new SqlDataAdapter mySqlCommand DataSet myDataSet new DataSet Retrieving rows from the Customers table myDataSet Customers You can write out the contents of myDataSet to an XML file using the WriteXml method. For example This writes an XML file named as shown in Listing . xml version standalone yes NewDataSet Customers CustomerID ALFKI CustomerID .