DataSet.GetXmlSchema DataSet.GetXmlSchema DataSet.GetXmlSchema DataSet.GetXmlSchema Method

定义

返回存储在 DataSet 中的数据的 XML 表示形式的 XML 架构。Returns the XML Schema for the XML representation of the data stored in the DataSet.

public:
 System::String ^ GetXmlSchema();
public string GetXmlSchema ();
member this.GetXmlSchema : unit -> string
Public Function GetXmlSchema () As String

返回

字符串,它是存储在 DataSet 中的数据的 XML 表示形式的 XML 架构。String that is the XML Schema for the XML representation of the data stored in the DataSet.

示例

下面的示例创建DataSetDataTable,然后以 XML 格式显示架构。The following example creates a DataSet and DataTable, and then displays the schema in XML format.

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() );
}
Private Shared Sub DemonstrateGetXml()
	' Create a DataSet with one table 
    ' containing two columns and 10 rows.
	Dim dataSet As New DataSet("dataSet")
	Dim table As DataTable = dataSet.Tables.Add("Items")
	table.Columns.Add("id", Type.GetType("System.Int32"))
	table.Columns.Add("Item", Type.GetType("System.String"))

	' Add ten rows.
	Dim row As DataRow
	Dim i As Integer
	For i = 0 To 9
		row = table.NewRow()
		row("id") = i
		row("Item")= "Item" & i
		table.Rows.Add(row)
	Next

	' Display the DataSet contents as XML.
	Console.WriteLine( dataSet.GetXml() )
End Sub

注解

调用此方法与调用WriteXmlSchema相同,只不过只写入主架构。Calling this method is identical to calling WriteXmlSchema, except that only the primary schema is written.

GetXmlSchema将 xml 作为字符串返回,因此需要的开销比WriteXmlSchema将 xml 写入文件的开销更多。GetXmlSchema returns XML as a string, and therefore requires more overhead than WriteXmlSchema to write XML to a file.

如果DataSet使用架构推理构建并使用 XML 或 Web 服务对其进行序列化,则列排序可能会更改。If you build a DataSet using schema inference and serialize it using XML or Web services, the column ordering may change.

适用于

另请参阅