ADO.NET: Read and Write XML
ADO.NET and DataSet can read and write XML schema and XML. For more information,
see
How do I...Use XML and the DataSet?
Schemas, or the tables, columns, constraints and so forth, of a DataSet
can be defined in several ways. One method is to create them using properties
and methods (Tables.Add, Columns.Add, and so on). This establishes
a schema within your DataSet that can be used as a container to hold data.
Another way is to use the SqlDataAdapter or OleDbDataAdapter. When you use
these commands, if the schema does not exist in a DataSet, it is created for
you.
XML is an intrinsic element of ADO.NET. Several methods that support XML have
been implemented. The GetXmlSchema method allows you to get the schema of a DataSet as an XSD schema.
For example, if you load a DataSet from the database,
you could get an XSD schema from it:
Console.WriteLine(myDataSet.GetXmlSchema());
C#
This returns an XSD compliant XML schema for the schema in your DataSet.
XML representation is also retrieved through the GetXml method.
Console.WriteLine(myDataSet.GetXml());
C#
The sample below loads data from a database, and then outputs the XSD Schema
and XML data.
C# ReadAndWriteXML.aspx
Microsoft .NET Framework SDK QuickStart Tutorials Version 2.0
Copyright � 2005 Microsoft Corporation. All rights reserved.
|