Lue englanniksi Muokkaa

Jaa


DataSet.GetXmlSchema Method

Definition

Returns the XML Schema for the XML representation of the data stored in the DataSet.

C#
public string GetXmlSchema();

Returns

String that is the XML Schema for the XML representation of the data stored in the DataSet.

Examples

The following example creates a DataSet and DataTable, and then displays the schema in XML format.

C#
private static void DemonstrateGetXml()
{
    // Create a DataSet with one table containing
    // two columns and 10 rows.
    DataSet dataSet = new DataSet("dataSet");
    DataTable table = dataSet.Tables.Add("Items");
    table.Columns.Add("id", typeof(int));
    table.Columns.Add("Item", typeof(string));

    // Add ten rows.
    DataRow row;
    for(int i = 0; i <10;i++)
    {
        row = table.NewRow();
        row["id"]= i;
        row["Item"]= "Item" + i;
        table.Rows.Add(row);
    }

    // Display the DataSet contents as XML.
    Console.WriteLine( dataSet.GetXml() );
}

Remarks

Calling this method is identical to calling WriteXmlSchema, except that only the primary schema is written.

GetXmlSchema returns XML as a string, and therefore requires more overhead than WriteXmlSchema to write XML to a file.

If you build a DataSet using schema inference and serialize it using XML or Web services, the column ordering may change.

Applies to

Tuote Versiot
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

See also