DataTable.WriteXmlSchema Metoda
Definice
Důležité
Některé informace platí pro předběžně vydaný produkt, který se může zásadně změnit, než ho výrobce nebo autor vydá. Microsoft neposkytuje žádné záruky, výslovné ani předpokládané, týkající se zde uváděných informací.
Zapíše aktuální datovou strukturu schématu DataTable XML.
Přetížení
| Name | Description |
|---|---|
| WriteXmlSchema(Stream) |
Zapíše aktuální datovou strukturu schématu DataTable XML do zadaného datového proudu. |
| WriteXmlSchema(TextWriter) |
Zapíše aktuální datovou strukturu DataTable jako schématu XML pomocí zadaného TextWriterschématu . |
| WriteXmlSchema(String) |
Zapíše aktuální datovou strukturu DataTable jako schématu XML do zadaného souboru. |
| WriteXmlSchema(XmlWriter) |
Zapíše aktuální datovou strukturu DataTable jako schématu XML pomocí zadaného XmlWriterschématu . |
| WriteXmlSchema(Stream, Boolean) |
Zapíše aktuální datovou strukturu schématu DataTable XML do zadaného datového proudu. Chcete-li uložit schéma pro tabulku a všechny její potomky, nastavte |
| WriteXmlSchema(TextWriter, Boolean) |
Zapíše aktuální datovou strukturu DataTable jako schématu XML pomocí zadaného TextWriterschématu . Chcete-li uložit schéma pro tabulku a všechny její potomky, nastavte |
| WriteXmlSchema(XmlWriter, Boolean) |
Zapíše aktuální datovou strukturu DataTable jako schématu XML pomocí zadaného XmlWriterschématu . Chcete-li uložit schéma pro tabulku a všechny její potomky, nastavte |
| WriteXmlSchema(String, Boolean) |
Zapíše aktuální datovou strukturu DataTable jako schématu XML do zadaného souboru. Chcete-li uložit schéma pro tabulku a všechny její potomky, nastavte |
Příklady
Následující konzolová aplikace vytvoří dvě DataTable instance, přidá každý do a DataSet, vytvoří DataRelation relaci dvou tabulek a pak použije metodu WriteXmlSchema k zápisu dat obsažených v nadřazené tabulce do TextWriter. Příklad ukazuje chování při nastavení parametru writeHierarchy na každou z jejích hodnot.
Note
Tento příklad ukazuje, jak použít jednu z přetížených verzí WriteXmlSchema pro další příklady, které mohou být k dispozici, viz jednotlivá témata přetížení.
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
V příkladu se v okně konzoly zobrazí následující výstup:
==============================
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>
Poznámky
WriteXmlSchema Metoda slouží k zápisu schématu DataTable do dokumentu XML. Schéma obsahuje definice tabulek, relací a omezení.
Schéma XML je zapsáno pomocí standardu XSD.
K zápisu dat do dokumentu XML použijte metodu WriteXml .
WriteXmlSchema(Stream)
- Zdroj:
- DataTable.cs
- Zdroj:
- DataTable.cs
- Zdroj:
- DataTable.cs
- Zdroj:
- DataTable.cs
- Zdroj:
- DataTable.cs
Zapíše aktuální datovou strukturu schématu DataTable XML do zadaného datového proudu.
public:
void WriteXmlSchema(System::IO::Stream ^ stream);
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Members from serialized types may use dynamic code generation.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
public void WriteXmlSchema(System.IO.Stream? stream);
public void WriteXmlSchema(System.IO.Stream? stream);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
public void WriteXmlSchema(System.IO.Stream? stream);
public void WriteXmlSchema(System.IO.Stream stream);
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Members from serialized types may use dynamic code generation.")>]
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")>]
member this.WriteXmlSchema : System.IO.Stream -> unit
member this.WriteXmlSchema : System.IO.Stream -> unit
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")>]
member this.WriteXmlSchema : System.IO.Stream -> unit
Public Sub WriteXmlSchema (stream As Stream)
Parametry
- stream
- Stream
Datový proud, do kterého se zapíše schéma XML.
- Atributy
Poznámky
WriteXmlSchema Metoda slouží k zápisu schématu DataTable do dokumentu XML. Schéma obsahuje definice tabulek, relací a omezení.
Schéma XML je zapsáno pomocí standardu XSD.
K zápisu dat do dokumentu XML použijte metodu WriteXml .
Viz také
Platí pro
WriteXmlSchema(TextWriter)
- Zdroj:
- DataTable.cs
- Zdroj:
- DataTable.cs
- Zdroj:
- DataTable.cs
- Zdroj:
- DataTable.cs
- Zdroj:
- DataTable.cs
Zapíše aktuální datovou strukturu DataTable jako schématu XML pomocí zadaného TextWriterschématu .
public:
void WriteXmlSchema(System::IO::TextWriter ^ writer);
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Members from serialized types may use dynamic code generation.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
public void WriteXmlSchema(System.IO.TextWriter? writer);
public void WriteXmlSchema(System.IO.TextWriter? writer);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
public void WriteXmlSchema(System.IO.TextWriter? writer);
public void WriteXmlSchema(System.IO.TextWriter writer);
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Members from serialized types may use dynamic code generation.")>]
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")>]
member this.WriteXmlSchema : System.IO.TextWriter -> unit
member this.WriteXmlSchema : System.IO.TextWriter -> unit
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")>]
member this.WriteXmlSchema : System.IO.TextWriter -> unit
Public Sub WriteXmlSchema (writer As TextWriter)
Parametry
- writer
- TextWriter
S TextWriter tím, s jakým se má psát.
- Atributy
Poznámky
WriteXmlSchema Metoda slouží k zápisu schématu DataTable do dokumentu XML. Schéma obsahuje definice tabulek, relací a omezení.
Schéma XML je zapsáno pomocí standardu XSD.
K zápisu dat do dokumentu XML použijte metodu WriteXml .
Viz také
Platí pro
WriteXmlSchema(String)
- Zdroj:
- DataTable.cs
- Zdroj:
- DataTable.cs
- Zdroj:
- DataTable.cs
- Zdroj:
- DataTable.cs
- Zdroj:
- DataTable.cs
Zapíše aktuální datovou strukturu DataTable jako schématu XML do zadaného souboru.
public:
void WriteXmlSchema(System::String ^ fileName);
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Members from serialized types may use dynamic code generation.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
public void WriteXmlSchema(string fileName);
public void WriteXmlSchema(string fileName);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
public void WriteXmlSchema(string fileName);
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Members from serialized types may use dynamic code generation.")>]
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")>]
member this.WriteXmlSchema : string -> unit
member this.WriteXmlSchema : string -> unit
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")>]
member this.WriteXmlSchema : string -> unit
Public Sub WriteXmlSchema (fileName As String)
Parametry
- fileName
- String
Název souboru, který se má použít.
- Atributy
Poznámky
WriteXmlSchema Metoda slouží k zápisu schématu DataTable do dokumentu XML. Schéma obsahuje definice tabulek, relací a omezení.
Schéma XML je zapsáno pomocí standardu XSD.
K zápisu dat do dokumentu XML použijte metodu WriteXml .
Viz také
Platí pro
WriteXmlSchema(XmlWriter)
- Zdroj:
- DataTable.cs
- Zdroj:
- DataTable.cs
- Zdroj:
- DataTable.cs
- Zdroj:
- DataTable.cs
- Zdroj:
- DataTable.cs
public:
void WriteXmlSchema(System::Xml::XmlWriter ^ writer);
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Members from serialized types may use dynamic code generation.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
public void WriteXmlSchema(System.Xml.XmlWriter? writer);
public void WriteXmlSchema(System.Xml.XmlWriter? writer);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
public void WriteXmlSchema(System.Xml.XmlWriter? writer);
public void WriteXmlSchema(System.Xml.XmlWriter writer);
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Members from serialized types may use dynamic code generation.")>]
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")>]
member this.WriteXmlSchema : System.Xml.XmlWriter -> unit
member this.WriteXmlSchema : System.Xml.XmlWriter -> unit
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")>]
member this.WriteXmlSchema : System.Xml.XmlWriter -> unit
Public Sub WriteXmlSchema (writer As XmlWriter)
Parametry
- Atributy
Poznámky
WriteXmlSchema Metoda slouží k zápisu schématu DataTable do dokumentu XML. Schéma obsahuje definice tabulek, relací a omezení.
Schéma XML je zapsáno pomocí standardu XSD.
K zápisu dat do dokumentu XML použijte metodu WriteXml .
Viz také
Platí pro
WriteXmlSchema(Stream, Boolean)
- Zdroj:
- DataTable.cs
- Zdroj:
- DataTable.cs
- Zdroj:
- DataTable.cs
- Zdroj:
- DataTable.cs
- Zdroj:
- DataTable.cs
Zapíše aktuální datovou strukturu schématu DataTable XML do zadaného datového proudu. Chcete-li uložit schéma pro tabulku a všechny její potomky, nastavte writeHierarchy parametr na true.
public:
void WriteXmlSchema(System::IO::Stream ^ stream, bool writeHierarchy);
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Members from serialized types may use dynamic code generation.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
public void WriteXmlSchema(System.IO.Stream? stream, bool writeHierarchy);
public void WriteXmlSchema(System.IO.Stream? stream, bool writeHierarchy);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
public void WriteXmlSchema(System.IO.Stream? stream, bool writeHierarchy);
public void WriteXmlSchema(System.IO.Stream stream, bool writeHierarchy);
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Members from serialized types may use dynamic code generation.")>]
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")>]
member this.WriteXmlSchema : System.IO.Stream * bool -> unit
member this.WriteXmlSchema : System.IO.Stream * bool -> unit
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")>]
member this.WriteXmlSchema : System.IO.Stream * bool -> unit
Public Sub WriteXmlSchema (stream As Stream, writeHierarchy As Boolean)
Parametry
- stream
- Stream
Datový proud, do kterého se zapíše schéma XML.
- writeHierarchy
- Boolean
Pokud truezapište schéma aktuální tabulky a všech jejích potomků. Pokud false (výchozí hodnota), zapište schéma pouze pro aktuální tabulku.
- Atributy
Poznámky
WriteXmlSchema Metoda slouží k zápisu schématu DataTable do dokumentu XML. Schéma obsahuje definice tabulek, relací a omezení.
Schéma XML je zapsáno pomocí standardu XSD.
K zápisu dat do dokumentu XML použijte metodu WriteXml .
Za normálních WriteXmlSchema okolností metoda zapisuje schéma pouze pro aktuální tabulku. Pokud chcete napsat schéma pro aktuální tabulku a její celý potomek, související tabulky, zavolejte metodu s parametrem nastaveným writeHierarchy na true.
Viz také
Platí pro
WriteXmlSchema(TextWriter, Boolean)
- Zdroj:
- DataTable.cs
- Zdroj:
- DataTable.cs
- Zdroj:
- DataTable.cs
- Zdroj:
- DataTable.cs
- Zdroj:
- DataTable.cs
Zapíše aktuální datovou strukturu DataTable jako schématu XML pomocí zadaného TextWriterschématu . Chcete-li uložit schéma pro tabulku a všechny její potomky, nastavte writeHierarchy parametr na true.
public:
void WriteXmlSchema(System::IO::TextWriter ^ writer, bool writeHierarchy);
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Members from serialized types may use dynamic code generation.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
public void WriteXmlSchema(System.IO.TextWriter? writer, bool writeHierarchy);
public void WriteXmlSchema(System.IO.TextWriter? writer, bool writeHierarchy);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
public void WriteXmlSchema(System.IO.TextWriter? writer, bool writeHierarchy);
public void WriteXmlSchema(System.IO.TextWriter writer, bool writeHierarchy);
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Members from serialized types may use dynamic code generation.")>]
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")>]
member this.WriteXmlSchema : System.IO.TextWriter * bool -> unit
member this.WriteXmlSchema : System.IO.TextWriter * bool -> unit
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")>]
member this.WriteXmlSchema : System.IO.TextWriter * bool -> unit
Public Sub WriteXmlSchema (writer As TextWriter, writeHierarchy As Boolean)
Parametry
- writer
- TextWriter
S TextWriter tím, s jakým se má psát.
- writeHierarchy
- Boolean
Pokud truezapište schéma aktuální tabulky a všech jejích potomků. Pokud false (výchozí hodnota), zapište schéma pouze pro aktuální tabulku.
- Atributy
Příklady
Následující konzolová aplikace vytvoří dvě DataTable instance, přidá každý do a DataSet, vytvoří DataRelation relaci dvou tabulek a pak použije metodu WriteXmlSchema k zápisu dat obsažených v nadřazené tabulce do TextWriter. Příklad ukazuje chování při nastavení parametru writeHierarchy na každou z jejích hodnot.
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
V příkladu se v okně konzoly zobrazí následující výstup:
==============================
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>
Poznámky
WriteXmlSchema Metoda slouží k zápisu schématu DataTable do dokumentu XML. Schéma obsahuje definice tabulek, relací a omezení.
Schéma XML je zapsáno pomocí standardu XSD.
K zápisu dat do dokumentu XML použijte metodu WriteXml .
Za normálních WriteXmlSchema okolností metoda zapisuje schéma pouze pro aktuální tabulku. Pokud chcete napsat schéma pro aktuální tabulku a její celý potomek, související tabulky, zavolejte metodu s parametrem nastaveným writeHierarchy na true.
Viz také
Platí pro
WriteXmlSchema(XmlWriter, Boolean)
- Zdroj:
- DataTable.cs
- Zdroj:
- DataTable.cs
- Zdroj:
- DataTable.cs
- Zdroj:
- DataTable.cs
- Zdroj:
- DataTable.cs
public:
void WriteXmlSchema(System::Xml::XmlWriter ^ writer, bool writeHierarchy);
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Members from serialized types may use dynamic code generation.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
public void WriteXmlSchema(System.Xml.XmlWriter? writer, bool writeHierarchy);
public void WriteXmlSchema(System.Xml.XmlWriter? writer, bool writeHierarchy);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
public void WriteXmlSchema(System.Xml.XmlWriter? writer, bool writeHierarchy);
public void WriteXmlSchema(System.Xml.XmlWriter writer, bool writeHierarchy);
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Members from serialized types may use dynamic code generation.")>]
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")>]
member this.WriteXmlSchema : System.Xml.XmlWriter * bool -> unit
member this.WriteXmlSchema : System.Xml.XmlWriter * bool -> unit
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")>]
member this.WriteXmlSchema : System.Xml.XmlWriter * bool -> unit
Public Sub WriteXmlSchema (writer As XmlWriter, writeHierarchy As Boolean)
Parametry
- writeHierarchy
- Boolean
Pokud truezapište schéma aktuální tabulky a všech jejích potomků. Pokud false (výchozí hodnota), zapište schéma pouze pro aktuální tabulku.
- Atributy
Poznámky
WriteXmlSchema Metoda slouží k zápisu schématu DataTable do dokumentu XML. Schéma obsahuje definice tabulek, relací a omezení.
Schéma XML je zapsáno pomocí standardu XSD.
K zápisu dat do dokumentu XML použijte metodu WriteXml .
Za normálních WriteXmlSchema okolností metoda zapisuje schéma pouze pro aktuální tabulku. Pokud chcete napsat schéma pro aktuální tabulku a její celý potomek, související tabulky, zavolejte metodu s parametrem nastaveným writeHierarchy na true.
Viz také
Platí pro
WriteXmlSchema(String, Boolean)
- Zdroj:
- DataTable.cs
- Zdroj:
- DataTable.cs
- Zdroj:
- DataTable.cs
- Zdroj:
- DataTable.cs
- Zdroj:
- DataTable.cs
Zapíše aktuální datovou strukturu DataTable jako schématu XML do zadaného souboru. Chcete-li uložit schéma pro tabulku a všechny její potomky, nastavte writeHierarchy parametr na true.
public:
void WriteXmlSchema(System::String ^ fileName, bool writeHierarchy);
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Members from serialized types may use dynamic code generation.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
public void WriteXmlSchema(string fileName, bool writeHierarchy);
public void WriteXmlSchema(string fileName, bool writeHierarchy);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")]
public void WriteXmlSchema(string fileName, bool writeHierarchy);
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Members from serialized types may use dynamic code generation.")>]
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")>]
member this.WriteXmlSchema : string * bool -> unit
member this.WriteXmlSchema : string * bool -> unit
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly.")>]
member this.WriteXmlSchema : string * bool -> unit
Public Sub WriteXmlSchema (fileName As String, writeHierarchy As Boolean)
Parametry
- fileName
- String
Název souboru, který se má použít.
- writeHierarchy
- Boolean
Pokud truezapište schéma aktuální tabulky a všech jejích potomků. Pokud false (výchozí hodnota), zapište schéma pouze pro aktuální tabulku.
- Atributy
Poznámky
WriteXmlSchema Metoda slouží k zápisu schématu DataTable do dokumentu XML. Schéma obsahuje definice tabulek, relací a omezení.
Schéma XML je zapsáno pomocí standardu XSD.
K zápisu dat do dokumentu XML použijte metodu WriteXml .
Za normálních WriteXmlSchema okolností metoda zapisuje schéma pouze pro aktuální tabulku. Pokud chcete napsat schéma pro aktuální tabulku a její celý potomek, související tabulky, zavolejte metodu s parametrem nastaveným writeHierarchy na true.