DataTable.WriteXmlSchema 方法
本文內容
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
將 DataTable 目前的資料結構撰寫成 XML 結構描述。
| WriteXmlSchema(Stream) |
將 DataTable 目前的資料結構撰寫成 XML 結構描述,寫入至指定的資料流。 |
| WriteXmlSchema(TextWriter) |
使用指定的 DataTable,將 TextWriter 目前的資料結構撰寫成 XML 結構描述。 |
| WriteXmlSchema(String) |
將 DataTable 目前的資料結構撰寫成 XML 結構描述,寫入至指定的檔案。 |
| WriteXmlSchema(XmlWriter) | |
| WriteXmlSchema(Stream, Boolean) |
將 DataTable 目前的資料結構撰寫成 XML 結構描述,寫入至指定的資料流。 若要儲存資料表及其所有子代的結構描述,請將 |
| WriteXmlSchema(TextWriter, Boolean) |
使用指定的 DataTable,將 TextWriter 目前的資料結構撰寫成 XML 結構描述。 若要儲存資料表及其所有子代的結構描述,請將 |
| WriteXmlSchema(XmlWriter, Boolean) |
使用指定的 DataTable,將 XmlWriter 目前的資料結構撰寫成 XML 結構描述。 若要儲存資料表及其所有子代的結構描述,請將 |
| WriteXmlSchema(String, Boolean) |
將 DataTable 目前的資料結構撰寫成 XML 結構描述,寫入至指定的檔案。 若要儲存資料表及其所有子代的結構描述,請將 |
下列主控台應用程式會建立兩DataTable個實例,將每個實例新增至 ,建立與兩個DataRelation資料表相關的 ,然後使用 WriteXmlSchema 方法將父資料表中包含的數據寫入至 TextWriterDataSet。 此範例示範將 參數設定 writeHierarchy 為其每個值時的行為。
注意
此範例示範如何使用 的其中一個多載版本 WriteXmlSchema 。如需其他可能可用的範例,請參閱個別的多載主題。
static void Main()
{
DataSet ds = new DataSet();
DataTable customerTable = GetCustomers();
DataTable orderTable = GetOrders();
ds.Tables.Add(customerTable);
ds.Tables.Add(orderTable);
ds.Relations.Add("CustomerOrder",
new DataColumn[] { customerTable.Columns[0] },
new DataColumn[] { orderTable.Columns[1] }, true);
System.IO.StringWriter writer = new System.IO.StringWriter();
customerTable.WriteXmlSchema(writer, false);
PrintOutput(writer, "Customer table, without hierarchy");
writer = new System.IO.StringWriter();
customerTable.WriteXmlSchema(writer, true);
PrintOutput(writer, "Customer table, with hierarchy");
Console.WriteLine("Press any key to continue.");
Console.ReadKey();
}
private static DataTable GetCustomers()
{
// Create sample Customers table, in order
// to demonstrate the behavior of the DataTableReader.
DataTable table = new DataTable();
// Create two columns, ID and Name.
DataColumn idColumn = table.Columns.Add("ID", typeof(System.Int32));
table.Columns.Add("Name", typeof(System.String));
// Set the ID column as the primary key column.
table.PrimaryKey = new DataColumn[] { idColumn };
table.Rows.Add(new object[] { 1, "Mary" });
table.Rows.Add(new object[] { 2, "Andy" });
table.Rows.Add(new object[] { 3, "Peter" });
table.Rows.Add(new object[] { 4, "Russ" });
table.AcceptChanges();
return table;
}
private static DataTable GetOrders()
{
// Create sample Customers table, in order
// to demonstrate the behavior of the DataTableReader.
DataTable table = new DataTable();
// Create three columns; OrderID, CustomerID, and OrderDate.
table.Columns.Add(new DataColumn("OrderID", typeof(System.Int32)));
table.Columns.Add(new DataColumn("CustomerID", typeof(System.Int32)));
table.Columns.Add(new DataColumn("OrderDate", typeof(System.DateTime)));
// Set the OrderID column as the primary key column.
table.PrimaryKey = new DataColumn[] { table.Columns[0] };
table.Rows.Add(new object[] { 1, 1, "12/2/2003" });
table.Rows.Add(new object[] { 2, 1, "1/3/2004" });
table.Rows.Add(new object[] { 3, 2, "11/13/2004" });
table.Rows.Add(new object[] { 4, 3, "5/16/2004" });
table.Rows.Add(new object[] { 5, 3, "5/22/2004" });
table.Rows.Add(new object[] { 6, 4, "6/15/2004" });
table.AcceptChanges();
return table;
}
private static void PrintOutput(System.IO.TextWriter writer,
string caption)
{
Console.WriteLine("==============================");
Console.WriteLine(caption);
Console.WriteLine("==============================");
Console.WriteLine(writer.ToString());
}
Sub Main()
Dim ds As New DataSet
Dim customerTable As DataTable = GetCustomers()
Dim orderTable As DataTable = GetOrders()
ds.Tables.Add(customerTable)
ds.Tables.Add(orderTable)
ds.Relations.Add("CustomerOrder", _
New DataColumn() {customerTable.Columns(0)}, _
New DataColumn() {orderTable.Columns(1)}, True)
Dim writer As New System.IO.StringWriter
customerTable.WriteXmlSchema(writer, False)
PrintOutput(writer, "Customer table, without hierarchy")
writer = New System.IO.StringWriter
customerTable.WriteXmlSchema(writer, True)
PrintOutput(writer, "Customer table, with hierarchy")
Console.WriteLine("Press any key to continue.")
Console.ReadKey()
End Sub
Private Function GetOrders() As DataTable
' Create sample Customers table, in order
' to demonstrate the behavior of the DataTableReader.
Dim table As New DataTable
' Create three columns, OrderID, CustomerID, and OrderDate.
table.Columns.Add(New DataColumn("OrderID", GetType(System.Int32)))
table.Columns.Add(New DataColumn("CustomerID", GetType(System.Int32)))
table.Columns.Add(New DataColumn("OrderDate", GetType(System.DateTime)))
' Set the OrderID column as the primary key column.
table.PrimaryKey = New DataColumn() {table.Columns(0)}
table.Rows.Add(New Object() {1, 1, #12/2/2003#})
table.Rows.Add(New Object() {2, 1, #1/3/2004#})
table.Rows.Add(New Object() {3, 2, #11/13/2004#})
table.Rows.Add(New Object() {4, 3, #5/16/2004#})
table.Rows.Add(New Object() {5, 3, #5/22/2004#})
table.Rows.Add(New Object() {6, 4, #6/15/2004#})
table.AcceptChanges()
Return table
End Function
Private Function GetCustomers() As DataTable
' Create sample Customers table, in order
' to demonstrate the behavior of the DataTableReader.
Dim table As New DataTable
' Create two columns, ID and Name.
Dim idColumn As DataColumn = table.Columns.Add("ID", GetType(System.Int32))
table.Columns.Add("Name", GetType(System.String))
' Set the ID column as the primary key column.
table.PrimaryKey = New DataColumn() {idColumn}
table.Rows.Add(New Object() {1, "Mary"})
table.Rows.Add(New Object() {2, "Andy"})
table.Rows.Add(New Object() {3, "Peter"})
table.Rows.Add(New Object() {4, "Russ"})
table.AcceptChanges()
Return table
End Function
Private Sub PrintOutput( _
ByVal writer As System.IO.TextWriter, ByVal caption As String)
Console.WriteLine("==============================")
Console.WriteLine(caption)
Console.WriteLine("==============================")
Console.WriteLine(writer.ToString())
End Sub
此範例會在主控台視窗中顯示以下輸出:
==============================
Customer table, without hierarchy
==============================
<?xml version="1.0" encoding="utf-16"?>
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:MainDataTable="Ta
ble1">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="Table1">
<xs:complexType>
<xs:sequence>
<xs:element name="ID" type="xs:int" />
<xs:element name="Name" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
<xs:unique name="Constraint1" msdata:PrimaryKey="true">
<xs:selector xpath=".//Table1" />
<xs:field xpath="ID" />
</xs:unique>
</xs:element>
</xs:schema>
==============================
Customer table, with hierarchy
==============================
<?xml version="1.0" encoding="utf-16"?>
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:MainDataTable="Table1">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="Table1">
<xs:complexType>
<xs:sequence>
<xs:element name="ID" type="xs:int" />
<xs:element name="Name" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Table2">
<xs:complexType>
<xs:sequence>
<xs:element name="OrderID" type="xs:int" />
<xs:element name="CustomerID" type="xs:int" minOccurs="0" />
<xs:element name="OrderDate" type="xs:dateTime" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
<xs:unique name="Constraint1" msdata:PrimaryKey="true">
<xs:selector xpath=".//Table1" />
<xs:field xpath="ID" />
</xs:unique>
<xs:unique name="Table2_Constraint1" msdata:ConstraintName="Constraint1" msdata:PrimaryKey="true">
<xs:selector xpath=".//Table2" />
<xs:field xpath="OrderID" />
</xs:unique>
<xs:keyref name="CustomerOrder" refer="Constraint1">
<xs:selector xpath=".//Table2" />
<xs:field xpath="CustomerID" />
</xs:keyref>
</xs:element>
</xs:schema>
WriteXmlSchema使用方法,將的DataTable架構寫入 XML 檔。 架構包含數據表、關聯性和條件約束定義。
XML 架構是使用 XSD 標準撰寫的。
若要將數據寫入 XML 檔,請使用 WriteXml 方法。
- 來源:
- DataTable.cs
- 來源:
- DataTable.cs
- 來源:
- DataTable.cs
將 DataTable 目前的資料結構撰寫成 XML 結構描述,寫入至指定的資料流。
public:
void WriteXmlSchema(System::IO::Stream ^ stream);
public void WriteXmlSchema (System.IO.Stream? stream);
public void WriteXmlSchema (System.IO.Stream stream);
member this.WriteXmlSchema : System.IO.Stream -> unit
Public Sub WriteXmlSchema (stream As Stream)
參數
- stream
- Stream
XML 結構描述將寫入其中的資料流。
備註
WriteXmlSchema使用方法,將的DataTable架構寫入 XML 檔。 架構包含數據表、關聯性和條件約束定義。
XML 架構是使用 XSD 標準撰寫的。
若要將數據寫入 XML 檔,請使用 WriteXml 方法。
另請參閱
適用於
.NET 9 及其他版本
| 產品 | 版本 |
|---|---|
| .NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
| .NET Framework | 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 |
- 來源:
- DataTable.cs
- 來源:
- DataTable.cs
- 來源:
- DataTable.cs
使用指定的 DataTable,將 TextWriter 目前的資料結構撰寫成 XML 結構描述。
public:
void WriteXmlSchema(System::IO::TextWriter ^ writer);
public void WriteXmlSchema (System.IO.TextWriter? writer);
public void WriteXmlSchema (System.IO.TextWriter writer);
member this.WriteXmlSchema : System.IO.TextWriter -> unit
Public Sub WriteXmlSchema (writer As TextWriter)
參數
- writer
- TextWriter
要用來寫入的 TextWriter。
備註
WriteXmlSchema使用方法,將的DataTable架構寫入 XML 檔。 架構包含數據表、關聯性和條件約束定義。
XML 架構是使用 XSD 標準撰寫的。
若要將數據寫入 XML 檔,請使用 WriteXml 方法。
另請參閱
適用於
.NET 9 及其他版本
| 產品 | 版本 |
|---|---|
| .NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
| .NET Framework | 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 |
- 來源:
- DataTable.cs
- 來源:
- DataTable.cs
- 來源:
- DataTable.cs
將 DataTable 目前的資料結構撰寫成 XML 結構描述,寫入至指定的檔案。
public:
void WriteXmlSchema(System::String ^ fileName);
public void WriteXmlSchema (string fileName);
member this.WriteXmlSchema : string -> unit
Public Sub WriteXmlSchema (fileName As String)
參數
- fileName
- String
要使用的檔案名稱。
備註
WriteXmlSchema使用方法,將的DataTable架構寫入 XML 檔。 架構包含數據表、關聯性和條件約束定義。
XML 架構是使用 XSD 標準撰寫的。
若要將數據寫入 XML 檔,請使用 WriteXml 方法。
另請參閱
適用於
.NET 9 及其他版本
| 產品 | 版本 |
|---|---|
| .NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
| .NET Framework | 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 |
- 來源:
- DataTable.cs
- 來源:
- DataTable.cs
- 來源:
- DataTable.cs
public:
void WriteXmlSchema(System::Xml::XmlWriter ^ writer);
public void WriteXmlSchema (System.Xml.XmlWriter? writer);
public void WriteXmlSchema (System.Xml.XmlWriter writer);
member this.WriteXmlSchema : System.Xml.XmlWriter -> unit
Public Sub WriteXmlSchema (writer As XmlWriter)
參數
備註
WriteXmlSchema使用方法,將的DataTable架構寫入 XML 檔。 架構包含數據表、關聯性和條件約束定義。
XML 架構是使用 XSD 標準撰寫的。
若要將數據寫入 XML 檔,請使用 WriteXml 方法。
另請參閱
適用於
.NET 9 及其他版本
| 產品 | 版本 |
|---|---|
| .NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
| .NET Framework | 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 |
- 來源:
- DataTable.cs
- 來源:
- DataTable.cs
- 來源:
- DataTable.cs
將 DataTable 目前的資料結構撰寫成 XML 結構描述,寫入至指定的資料流。 若要儲存資料表及其所有子代的結構描述,請將 writeHierarchy 參數設定為 true。
public:
void WriteXmlSchema(System::IO::Stream ^ stream, bool writeHierarchy);
public void WriteXmlSchema (System.IO.Stream? stream, bool writeHierarchy);
public void WriteXmlSchema (System.IO.Stream stream, bool writeHierarchy);
member this.WriteXmlSchema : System.IO.Stream * bool -> unit
Public Sub WriteXmlSchema (stream As Stream, writeHierarchy As Boolean)
參數
- stream
- Stream
XML 結構描述將寫入其中的資料流。
- writeHierarchy
- Boolean
如果為 true,就會寫入目前資料表及其所有子代的結構描述。 如果為 false (預設值),就只會寫入目前資料表的結構描述。
備註
WriteXmlSchema使用方法,將的DataTable架構寫入 XML 檔。 架構包含數據表、關聯性和條件約束定義。
XML 架構是使用 XSD 標準撰寫的。
若要將數據寫入 XML 檔,請使用 WriteXml 方法。
一般而言, WriteXmlSchema 方法只會寫入目前數據表的架構。 若要撰寫目前資料表及其整個子系相關資料表的架構,請呼叫 方法,並將 writeHierarchy 參數設定為 true。
另請參閱
適用於
.NET 9 及其他版本
| 產品 | 版本 |
|---|---|
| .NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
| .NET Framework | 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 |
- 來源:
- DataTable.cs
- 來源:
- DataTable.cs
- 來源:
- DataTable.cs
使用指定的 DataTable,將 TextWriter 目前的資料結構撰寫成 XML 結構描述。 若要儲存資料表及其所有子代的結構描述,請將 writeHierarchy 參數設定為 true。
public:
void WriteXmlSchema(System::IO::TextWriter ^ writer, bool writeHierarchy);
public void WriteXmlSchema (System.IO.TextWriter? writer, bool writeHierarchy);
public void WriteXmlSchema (System.IO.TextWriter writer, bool writeHierarchy);
member this.WriteXmlSchema : System.IO.TextWriter * bool -> unit
Public Sub WriteXmlSchema (writer As TextWriter, writeHierarchy As Boolean)
參數
- writer
- TextWriter
要用來寫入的 TextWriter。
- writeHierarchy
- Boolean
如果為 true,就會寫入目前資料表及其所有子代的結構描述。 如果為 false (預設值),就只會寫入目前資料表的結構描述。
範例
下列主控台應用程式會建立兩DataTable個實例,將每個實例新增至 ,建立與兩個DataRelation資料表相關的 ,然後使用 WriteXmlSchema 方法將父資料表中包含的數據寫入至 TextWriterDataSet。 此範例示範將 參數設定 writeHierarchy 為其每個值時的行為。
static void Main()
{
DataSet ds = new DataSet();
DataTable customerTable = GetCustomers();
DataTable orderTable = GetOrders();
ds.Tables.Add(customerTable);
ds.Tables.Add(orderTable);
ds.Relations.Add("CustomerOrder",
new DataColumn[] { customerTable.Columns[0] },
new DataColumn[] { orderTable.Columns[1] }, true);
System.IO.StringWriter writer = new System.IO.StringWriter();
customerTable.WriteXmlSchema(writer, false);
PrintOutput(writer, "Customer table, without hierarchy");
writer = new System.IO.StringWriter();
customerTable.WriteXmlSchema(writer, true);
PrintOutput(writer, "Customer table, with hierarchy");
Console.WriteLine("Press any key to continue.");
Console.ReadKey();
}
private static DataTable GetCustomers()
{
// Create sample Customers table, in order
// to demonstrate the behavior of the DataTableReader.
DataTable table = new DataTable();
// Create two columns, ID and Name.
DataColumn idColumn = table.Columns.Add("ID", typeof(System.Int32));
table.Columns.Add("Name", typeof(System.String));
// Set the ID column as the primary key column.
table.PrimaryKey = new DataColumn[] { idColumn };
table.Rows.Add(new object[] { 1, "Mary" });
table.Rows.Add(new object[] { 2, "Andy" });
table.Rows.Add(new object[] { 3, "Peter" });
table.Rows.Add(new object[] { 4, "Russ" });
table.AcceptChanges();
return table;
}
private static DataTable GetOrders()
{
// Create sample Customers table, in order
// to demonstrate the behavior of the DataTableReader.
DataTable table = new DataTable();
// Create three columns; OrderID, CustomerID, and OrderDate.
table.Columns.Add(new DataColumn("OrderID", typeof(System.Int32)));
table.Columns.Add(new DataColumn("CustomerID", typeof(System.Int32)));
table.Columns.Add(new DataColumn("OrderDate", typeof(System.DateTime)));
// Set the OrderID column as the primary key column.
table.PrimaryKey = new DataColumn[] { table.Columns[0] };
table.Rows.Add(new object[] { 1, 1, "12/2/2003" });
table.Rows.Add(new object[] { 2, 1, "1/3/2004" });
table.Rows.Add(new object[] { 3, 2, "11/13/2004" });
table.Rows.Add(new object[] { 4, 3, "5/16/2004" });
table.Rows.Add(new object[] { 5, 3, "5/22/2004" });
table.Rows.Add(new object[] { 6, 4, "6/15/2004" });
table.AcceptChanges();
return table;
}
private static void PrintOutput(System.IO.TextWriter writer, string caption)
{
Console.WriteLine("==============================");
Console.WriteLine(caption);
Console.WriteLine("==============================");
Console.WriteLine(writer.ToString());
}
Sub Main()
Dim ds As New DataSet
Dim customerTable As DataTable = GetCustomers()
Dim orderTable As DataTable = GetOrders()
ds.Tables.Add(customerTable)
ds.Tables.Add(orderTable)
ds.Relations.Add("CustomerOrder", _
New DataColumn() {customerTable.Columns(0)}, _
New DataColumn() {orderTable.Columns(1)}, True)
Dim writer As New System.IO.StringWriter
customerTable.WriteXmlSchema(writer, False)
PrintOutput(writer, "Customer table, without hierarchy")
writer = New System.IO.StringWriter
customerTable.WriteXmlSchema(writer, True)
PrintOutput(writer, "Customer table, with hierarchy")
Console.WriteLine("Press any key to continue.")
Console.ReadKey()
End Sub
Private Function GetOrders() As DataTable
' Create sample Customers table, in order
' to demonstrate the behavior of the DataTableReader.
Dim table As New DataTable
' Create three columns, OrderID, CustomerID, and OrderDate.
table.Columns.Add(New DataColumn("OrderID", GetType(System.Int32)))
table.Columns.Add(New DataColumn("CustomerID", GetType(System.Int32)))
table.Columns.Add(New DataColumn("OrderDate", GetType(System.DateTime)))
' Set the OrderID column as the primary key column.
table.PrimaryKey = New DataColumn() {table.Columns(0)}
table.Rows.Add(New Object() {1, 1, #12/2/2003#})
table.Rows.Add(New Object() {2, 1, #1/3/2004#})
table.Rows.Add(New Object() {3, 2, #11/13/2004#})
table.Rows.Add(New Object() {4, 3, #5/16/2004#})
table.Rows.Add(New Object() {5, 3, #5/22/2004#})
table.Rows.Add(New Object() {6, 4, #6/15/2004#})
table.AcceptChanges()
Return table
End Function
Private Function GetCustomers() As DataTable
' Create sample Customers table, in order
' to demonstrate the behavior of the DataTableReader.
Dim table As New DataTable
' Create two columns, ID and Name.
Dim idColumn As DataColumn = table.Columns.Add("ID", _
GetType(System.Int32))
table.Columns.Add("Name", GetType(System.String))
' Set the ID column as the primary key column.
table.PrimaryKey = New DataColumn() {idColumn}
table.Rows.Add(New Object() {1, "Mary"})
table.Rows.Add(New Object() {2, "Andy"})
table.Rows.Add(New Object() {3, "Peter"})
table.Rows.Add(New Object() {4, "Russ"})
table.AcceptChanges()
Return table
End Function
Private Sub PrintOutput( _
ByVal writer As System.IO.TextWriter, ByVal caption As String)
Console.WriteLine("==============================")
Console.WriteLine(caption)
Console.WriteLine("==============================")
Console.WriteLine(writer.ToString())
End Sub
此範例會在主控台視窗中顯示以下輸出:
==============================
Customer table, without hierarchy
==============================
<?xml version="1.0" encoding="utf-16"?>
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:MainDataTable="Ta
ble1">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="Table1">
<xs:complexType>
<xs:sequence>
<xs:element name="ID" type="xs:int" />
<xs:element name="Name" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
<xs:unique name="Constraint1" msdata:PrimaryKey="true">
<xs:selector xpath=".//Table1" />
<xs:field xpath="ID" />
</xs:unique>
</xs:element>
</xs:schema>
==============================
Customer table, with hierarchy
==============================
<?xml version="1.0" encoding="utf-16"?>
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:MainDataTable="Table1">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="Table1">
<xs:complexType>
<xs:sequence>
<xs:element name="ID" type="xs:int" />
<xs:element name="Name" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Table2">
<xs:complexType>
<xs:sequence>
<xs:element name="OrderID" type="xs:int" />
<xs:element name="CustomerID" type="xs:int" minOccurs="0" />
<xs:element name="OrderDate" type="xs:dateTime" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
<xs:unique name="Constraint1" msdata:PrimaryKey="true">
<xs:selector xpath=".//Table1" />
<xs:field xpath="ID" />
</xs:unique>
<xs:unique name="Table2_Constraint1" msdata:ConstraintName="Constraint1" msdata:PrimaryKey="true">
<xs:selector xpath=".//Table2" />
<xs:field xpath="OrderID" />
</xs:unique>
<xs:keyref name="CustomerOrder" refer="Constraint1">
<xs:selector xpath=".//Table2" />
<xs:field xpath="CustomerID" />
</xs:keyref>
</xs:element>
</xs:schema>
備註
WriteXmlSchema使用方法,將的DataTable架構寫入 XML 檔。 架構包含數據表、關聯性和條件約束定義。
XML 架構是使用 XSD 標準撰寫的。
若要將數據寫入 XML 檔,請使用 WriteXml 方法。
一般而言, WriteXmlSchema 方法只會寫入目前數據表的架構。 若要撰寫目前資料表及其整個子系相關資料表的架構,請呼叫 方法,並將 writeHierarchy 參數設定為 true。
另請參閱
適用於
.NET 9 及其他版本
| 產品 | 版本 |
|---|---|
| .NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
| .NET Framework | 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 |
- 來源:
- DataTable.cs
- 來源:
- DataTable.cs
- 來源:
- DataTable.cs
public:
void WriteXmlSchema(System::Xml::XmlWriter ^ writer, bool writeHierarchy);
public void WriteXmlSchema (System.Xml.XmlWriter? writer, bool writeHierarchy);
public void WriteXmlSchema (System.Xml.XmlWriter writer, bool writeHierarchy);
member this.WriteXmlSchema : System.Xml.XmlWriter * bool -> unit
Public Sub WriteXmlSchema (writer As XmlWriter, writeHierarchy As Boolean)
參數
- writeHierarchy
- Boolean
如果為 true,就會寫入目前資料表及其所有子代的結構描述。 如果為 false (預設值),就只會寫入目前資料表的結構描述。
備註
WriteXmlSchema使用方法,將的DataTable架構寫入 XML 檔。 架構包含數據表、關聯性和條件約束定義。
XML 架構是使用 XSD 標準撰寫的。
若要將數據寫入 XML 檔,請使用 WriteXml 方法。
一般而言, WriteXmlSchema 方法只會寫入目前數據表的架構。 若要撰寫目前資料表及其整個子系相關資料表的架構,請呼叫 方法,並將 writeHierarchy 參數設定為 true。
另請參閱
適用於
.NET 9 及其他版本
| 產品 | 版本 |
|---|---|
| .NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
| .NET Framework | 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 |
- 來源:
- DataTable.cs
- 來源:
- DataTable.cs
- 來源:
- DataTable.cs
將 DataTable 目前的資料結構撰寫成 XML 結構描述,寫入至指定的檔案。 若要儲存資料表及其所有子代的結構描述,請將 writeHierarchy 參數設定為 true。
public:
void WriteXmlSchema(System::String ^ fileName, bool writeHierarchy);
public void WriteXmlSchema (string fileName, bool writeHierarchy);
member this.WriteXmlSchema : string * bool -> unit
Public Sub WriteXmlSchema (fileName As String, writeHierarchy As Boolean)
參數
- fileName
- String
要使用的檔案名稱。
- writeHierarchy
- Boolean
如果為 true,就會寫入目前資料表及其所有子代的結構描述。 如果為 false (預設值),就只會寫入目前資料表的結構描述。
備註
WriteXmlSchema使用方法,將的DataTable架構寫入 XML 檔。 架構包含數據表、關聯性和條件約束定義。
XML 架構是使用 XSD 標準撰寫的。
若要將數據寫入 XML 檔,請使用 WriteXml 方法。
一般而言, WriteXmlSchema 方法只會寫入目前數據表的架構。 若要撰寫目前資料表及其整個子系相關資料表的架構,請呼叫 方法,並將 writeHierarchy 參數設定為 true。
另請參閱
適用於
.NET 9 及其他版本
| 產品 | 版本 |
|---|---|
| .NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
| .NET Framework | 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 |