DataSet.WriteXmlSchema 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
將結構寫 DataSet 成 XML 架構。
多載
| 名稱 | Description |
|---|---|
| WriteXmlSchema(String, Converter<Type,String>) |
將 DataSet 結構以 XML 架構寫入檔案。 |
| WriteXmlSchema(Stream) | |
| WriteXmlSchema(TextWriter) |
將 DataSet 結構以 XML 架構寫入指定的 TextWriter 物件。 |
| WriteXmlSchema(String) |
將 DataSet 結構以 XML 架構寫入檔案。 |
| WriteXmlSchema(XmlWriter) | |
| WriteXmlSchema(Stream, Converter<Type,String>) | |
| WriteXmlSchema(TextWriter, Converter<Type,String>) |
將 DataSet 結構寫成指定的 XML 結構 TextWriter。 |
| WriteXmlSchema(XmlWriter, Converter<Type,String>) |
WriteXmlSchema(String, Converter<Type,String>)
將 DataSet 結構以 XML 架構寫入檔案。
public:
void WriteXmlSchema(System::String ^ fileName, Converter<Type ^, System::String ^> ^ multipleTargetConverter);
public void WriteXmlSchema(string fileName, Converter<Type,string> multipleTargetConverter);
member this.WriteXmlSchema : string * Converter<Type, string> -> unit
Public Sub WriteXmlSchema (fileName As String, multipleTargetConverter As Converter(Of Type, String))
參數
- fileName
- String
要寫入的檔案名稱。
適用於
WriteXmlSchema(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)
參數
範例
以下範例建立一個新 FileStream 物件,該物件會傳遞給寫入結構到磁碟的方法 WriteXmlSchema 。
private void WriteSchemaWithFileStream(DataSet thisDataSet)
{
// Set the file path and name. Modify this for your purposes.
string filename="Schema.xml";
// Create the FileStream object with the file name.
// Use FileMode.Create.
System.IO.FileStream stream =
new System.IO.FileStream(filename,System.IO.FileMode.Create);
// Write the schema to the file.
thisDataSet.WriteXmlSchema(stream);
// Close the FileStream.
stream.Close();
}
Private Sub WriteSchemaWithFileStream(thisDataSet As DataSet)
' Set the file path and name. Modify this for your purposes.
Dim filename As String = "Schema.xml"
' Create the FileStream object with the file name.
' Use FileMode.Create.
Dim stream As New System.IO.FileStream _
(filename, System.IO.FileMode.Create)
' Write the schema to the file.
thisDataSet.WriteXmlSchema(stream)
' Close the FileStream.
stream.Close()
End Sub
備註
使用 WriteXmlSchema 將 a 的結構 DataSet 寫成 XML 文件的方法。 該結構包含表格、關聯與約束定義。 要為 XML 文件撰寫結構,請使用該 WriteXmlSchema 方法。
XML 架構是依據 XSD 標準撰寫的。
若要將資料寫入 XML 文件,請使用以下 WriteXml 方法。
由 Stream 衍生的類別包括 BufferedStream、 FileStream、 MemoryStream、 NetworkStream和 。
另請參閱
使用 ADO.NET
適用於
WriteXmlSchema(TextWriter)
將 DataSet 結構以 XML 架構寫入指定的 TextWriter 物件。
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 來寫作的對象。
範例
以下範例會建立 System.Text.StringBuilder 一個物件,用來建立新的 System.IO.StringWriter。 StringWriter將 傳遞給WriteXmlSchema方法,產生的字串會印到主控台視窗。
private void WriteSchemaWithStringWriter(DataSet thisDataSet)
{
// Create a new StringBuilder object.
System.Text.StringBuilder builder = new System.Text.StringBuilder();
// Create the StringWriter object with the StringBuilder object.
System.IO.StringWriter writer = new System.IO.StringWriter(builder);
// Write the schema into the StringWriter.
thisDataSet.WriteXmlSchema(writer);
// Print the string to the console window.
Console.WriteLine(writer.ToString());
}
Private Sub WriteSchemaWithStringWriter(thisDataSet As DataSet)
' Create a new StringBuilder object.
Dim builder As New System.Text.StringBuilder()
' Create the StringWriter object with the StringBuilder object.
Dim writer As New System.IO.StringWriter(builder)
' Write the schema into the StringWriter.
thisDataSet.WriteXmlSchema(writer)
' Print the string to the console window.
Console.WriteLine(writer.ToString())
End Sub
備註
使用 WriteXmlSchema 將 a 的結構 DataSet 寫成 XML 文件的方法。 該結構包含表格、關聯與約束定義。 要為 XML 文件撰寫結構,請使用該 WriteXmlSchema 方法。
XML 架構是依據 XSD 標準撰寫的。
若要將資料寫入 XML 文件,請使用以下 WriteXml 方法。
從該System.IO.TextWriter類別推導的類別包括 System.Web.HttpWriter、 System.CodeDom.Compiler.IndentedTextWriter、 System.Web.UI.HtmlTextWriterSystem.IO.StreamWriterSystem.IO.StringWriter、 和 。
另請參閱
使用 ADO.NET
適用於
WriteXmlSchema(String)
將 DataSet 結構以 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
要寫入的檔名(包括路徑)。
例外狀況
範例
private void WriteSchemaToFile(DataSet thisDataSet)
{
// Set the file path and name. Modify this for your purposes.
string filename="Schema.xml";
// Write the schema to the file.
thisDataSet.WriteXmlSchema(filename);
}
Private Sub WriteSchemaToFile(thisDataSet As DataSet)
' Set the file path and name. Modify this for your purposes.
Dim filename As String = "Schema.xml"
' Write the schema to the file.
thisDataSet.WriteXmlSchema(filename)
End Sub
備註
使用 WriteXmlSchema 將 a 的結構 DataSet 寫成 XML 文件的方法。 該結構包含表格、關聯與約束定義。 要為 XML 文件撰寫結構,請使用該 WriteXmlSchema 方法。
XML 架構是依據 XSD 標準撰寫的。
若要將資料寫入 XML 文件,請使用以下 WriteXml 方法。
另請參閱
使用 ADO.NET
適用於
WriteXmlSchema(XmlWriter)
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)
參數
範例
以下範例 System.IO.FileStream 建立一個帶有指定路徑的新物件。 FileStream物件用來創造物件XmlTextWriter。 接著會用物件呼叫XmlTextWriter該WriteXmlSchema方法,將結構寫入磁碟。
private void WriteSchemaWithXmlTextWriter(DataSet thisDataSet)
{
// Set the file path and name. Modify this for your purposes.
string filename="SchemaDoc.xml";
// Create a FileStream object with the file path and name.
System.IO.FileStream stream = new System.IO.FileStream
(filename,System.IO.FileMode.Create);
// Create a new XmlTextWriter object with the FileStream.
System.Xml.XmlTextWriter writer =
new System.Xml.XmlTextWriter(stream,
System.Text.Encoding.Unicode);
// Write the schema into the DataSet and close the reader.
thisDataSet.WriteXmlSchema(writer );
writer.Close();
}
Private Sub WriteSchemaWithXmlTextWriter(thisDataSet As DataSet)
' Set the file path and name. Modify this for your purposes.
Dim filename As String = "SchemaDoc.xml"
' Create a FileStream object with the file path and name.
Dim stream As New System.IO.FileStream _
(filename, System.IO.FileMode.Create)
' Create a new XmlTextWriter object with the FileStream.
Dim writer As New System.Xml.XmlTextWriter _
(stream, System.Text.Encoding.Unicode)
' Write the schema into the DataSet and close the reader.
thisDataSet.WriteXmlSchema(writer)
writer.Close()
End Sub
備註
使用 WriteXmlSchema 將 a 的結構 DataSet 寫成 XML 文件的方法。 該結構包含表格、關聯與約束定義。 要為 XML 文件撰寫結構,請使用該 WriteXmlSchema 方法。
XML 架構是依據 XSD 標準撰寫的。
若要將資料寫入 XML 文件,請使用以下 WriteXml 方法。
繼承自該System.Xml.XmlWriter類別的一個類別是 。XmlTextWriter
另請參閱
使用 ADO.NET
適用於
WriteXmlSchema(Stream, Converter<Type,String>)
public:
void WriteXmlSchema(System::IO::Stream ^ stream, Converter<Type ^, System::String ^> ^ multipleTargetConverter);
public void WriteXmlSchema(System.IO.Stream stream, Converter<Type,string> multipleTargetConverter);
member this.WriteXmlSchema : System.IO.Stream * Converter<Type, string> -> unit
Public Sub WriteXmlSchema (stream As Stream, multipleTargetConverter As Converter(Of Type, String))
參數
適用於
WriteXmlSchema(TextWriter, Converter<Type,String>)
將 DataSet 結構寫成指定的 XML 結構 TextWriter。
public:
void WriteXmlSchema(System::IO::TextWriter ^ writer, Converter<Type ^, System::String ^> ^ multipleTargetConverter);
public void WriteXmlSchema(System.IO.TextWriter writer, Converter<Type,string> multipleTargetConverter);
member this.WriteXmlSchema : System.IO.TextWriter * Converter<Type, string> -> unit
Public Sub WriteXmlSchema (writer As TextWriter, multipleTargetConverter As Converter(Of Type, String))
參數
- writer
- TextWriter
一個 TextWriter 可以寫入的物件。
適用於
WriteXmlSchema(XmlWriter, Converter<Type,String>)
public:
void WriteXmlSchema(System::Xml::XmlWriter ^ writer, Converter<Type ^, System::String ^> ^ multipleTargetConverter);
public void WriteXmlSchema(System.Xml.XmlWriter writer, Converter<Type,string> multipleTargetConverter);
member this.WriteXmlSchema : System.Xml.XmlWriter * Converter<Type, string> -> unit
Public Sub WriteXmlSchema (writer As XmlWriter, multipleTargetConverter As Converter(Of Type, String))