XmlTextWriter 构造函数
定义
创建 XmlTextWriter 类的实例。Creates an instance of the XmlTextWriter class.
重载
| XmlTextWriter(TextWriter) |
使用指定的 TextWriter 创建 |
| XmlTextWriter(Stream, Encoding) |
使用指定的流和编码方式创建 |
| XmlTextWriter(String, Encoding) |
使用指定的文件创建 XmlTextWriter 类的实例。Creates an instance of the XmlTextWriter class using the specified file. |
注解
备注
从 .NET Framework 2.0 开始,我们建议 XmlWriter 使用 XmlWriter.Create 方法和类创建实例, XmlWriterSettings 以利用新功能。Starting with the .NET Framework 2.0, we recommend that you create XmlWriter instances by using the XmlWriter.Create method and the XmlWriterSettings class to take advantage of new functionality.
XmlTextWriter(TextWriter)
使用指定的 TextWriter 创建 XmlTextWriter 类的实例。Creates an instance of the XmlTextWriter class using the specified TextWriter.
public:
XmlTextWriter(System::IO::TextWriter ^ w);
public XmlTextWriter (System.IO.TextWriter w);
new System.Xml.XmlTextWriter : System.IO.TextWriter -> System.Xml.XmlTextWriter
Public Sub New (w As TextWriter)
参数
要向其中进行写入的 TextWriter。The TextWriter to write to. 假定 TextWriter 已设置为正确的编码方式。It is assumed that the TextWriter is already set to the correct encoding.
注解
备注
从 .NET Framework 2.0 开始,我们建议 XmlWriter 使用 XmlWriter.Create 方法和类创建实例, XmlWriterSettings 以利用新功能。Starting with the .NET Framework 2.0, we recommend that you create XmlWriter instances by using the XmlWriter.Create method and the XmlWriterSettings class to take advantage of new functionality.
适用于
XmlTextWriter(Stream, Encoding)
使用指定的流和编码方式创建 XmlTextWriter 类的实例。Creates an instance of the XmlTextWriter class using the specified stream and encoding.
public:
XmlTextWriter(System::IO::Stream ^ w, System::Text::Encoding ^ encoding);
public XmlTextWriter (System.IO.Stream w, System.Text.Encoding? encoding);
public XmlTextWriter (System.IO.Stream w, System.Text.Encoding encoding);
new System.Xml.XmlTextWriter : System.IO.Stream * System.Text.Encoding -> System.Xml.XmlTextWriter
Public Sub New (w As Stream, encoding As Encoding)
参数
- w
- Stream
要对其写入的流。The stream to which you want to write.
- encoding
- Encoding
要生成的编码。The encoding to generate. 如果编码方式为 null,则它以 UTF-8 的形式写出流并忽略 ProcessingInstruction 中的编码特性。If encoding is null it writes out the stream as UTF-8 and omits the encoding attribute from the ProcessingInstruction.
例外
该编码方式不受支持或无法写入流。The encoding is not supported or the stream cannot be written to.
w 为 null。w is null.
注解
备注
从 .NET Framework 2.0 开始,我们建议 XmlWriter 使用 XmlWriter.Create 方法和类创建实例, XmlWriterSettings 以利用新功能。Starting with the .NET Framework 2.0, we recommend that you create XmlWriter instances by using the XmlWriter.Create method and the XmlWriterSettings class to take advantage of new functionality.
适用于
XmlTextWriter(String, Encoding)
使用指定的文件创建 XmlTextWriter 类的实例。Creates an instance of the XmlTextWriter class using the specified file.
public:
XmlTextWriter(System::String ^ filename, System::Text::Encoding ^ encoding);
public XmlTextWriter (string filename, System.Text.Encoding? encoding);
public XmlTextWriter (string filename, System.Text.Encoding encoding);
new System.Xml.XmlTextWriter : string * System.Text.Encoding -> System.Xml.XmlTextWriter
Public Sub New (filename As String, encoding As Encoding)
参数
- filename
- String
要写入的文件名。The filename to write to. 如果该文件存在,它将截断该文件并用新内容将其覆盖。If the file exists, it truncates it and overwrites it with the new content.
- encoding
- Encoding
要生成的编码。The encoding to generate. 如果编码方式为 null,它将以 UTF-8 的形式写出该文件,并忽略 ProcessingInstruction 中的编码特性。If encoding is null it writes the file out as UTF-8, and omits the encoding attribute from the ProcessingInstruction.
例外
编码方式不受支持;文件名为空;仅包含空格,或者包含一个或多个无效字符。The encoding is not supported; the filename is empty, contains only white space, or contains one or more invalid characters.
访问被拒绝。Access is denied.
文件名为 null。The filename is null.
未找到要写入的目录。The directory to write to is not found.
文件名中包含不正确或无效的文件名、目录名或卷标语法。The filename includes an incorrect or invalid syntax for file name, directory name, or volume label syntax.
调用方没有所要求的权限。The caller does not have the required permission.
注解
备注
从 .NET Framework 2.0 开始,我们建议 XmlWriter 使用 XmlWriter.Create 方法和类创建实例, XmlWriterSettings 以利用新功能。Starting with the .NET Framework 2.0, we recommend that you create XmlWriter instances by using the XmlWriter.Create method and the XmlWriterSettings class to take advantage of new functionality.