XmlWriter XmlWriter XmlWriter XmlWriter Class

定义

表示一个写入器,该写入器提供一种快速、非缓存和只进方式以生成包含 XML 数据的流或文件。Represents a writer that provides a fast, non-cached, forward-only way to generate streams or files that contain XML data.

public ref class XmlWriter abstract : IDisposable
public abstract class XmlWriter : IDisposable
type XmlWriter = class
    interface IDisposable
Public MustInherit Class XmlWriter
Implements IDisposable
继承
XmlWriterXmlWriterXmlWriterXmlWriter
派生
实现

示例

下面的代码示例演示如何使用异步 API 来生成 XML。The following example code shows how to use the asynchronous API to generate XML.

async Task TestWriter(Stream stream)   
{  
    XmlWriterSettings settings = new XmlWriterSettings();  
    settings.Async = true;  

    using (XmlWriter writer = XmlWriter.Create(stream, settings)) {  
        await writer.WriteStartElementAsync("pf", "root", "http://ns");  
        await writer.WriteStartElementAsync(null, "sub", null);  
        await writer.WriteAttributeStringAsync(null, "att", null, "val");  
        await writer.WriteStringAsync("text");  
        await writer.WriteEndElementAsync();  
        await writer.WriteProcessingInstructionAsync("pName", "pValue");  
        await writer.WriteCommentAsync("cValue");  
        await writer.WriteCDataAsync("cdata value");  
        await writer.WriteEndElementAsync();  
        await writer.FlushAsync();  
    }  
}  

注解

XmlWriter类将 XML 数据写入到流、 文件、 文本读取器或字符串。The XmlWriter class writes XML data to a stream, file, text reader, or string. 它支持 W3C可扩展标记语言 (XML) 1.0 (第四版)命名空间中 XML 1.0 (第三版)建议。It supports the W3C Extensible Markup Language (XML) 1.0 (fourth edition) and Namespaces in XML 1.0 (third edition) recommendations.

成员XmlWriter类使您能够:The members of the XmlWriter class enable you to:

  • 检查字符是不是合法的 XML 字符,元素和属性的名称是不是有效的 XML 名称。Verify that the characters are legal XML characters and that element and attribute names are valid XML names.

  • 检查 XML 文档的格式是否正确。Verify that the XML document is well-formed.

  • 将二进制字节编码为 Base64 或 BinHex,并写出结果文本。Encode binary bytes as Base64 or BinHex, and write out the resulting text.

  • 通过使用公共语言运行时类型而不字符串,可以避免不得不手动执行值的转换传递值。Pass values by using common language runtime types instead of strings, to avoid having to manually perform value conversions.

  • 将多个文档写入一个输出流。Write multiple documents to one output stream.

  • 写出有效的名称、限定名和名称标记。Write valid names, qualified names, and name tokens.

本节内容:In this section:

创建 XML 编写器 Creating an XML writer
指定的输出格式 Specifying the output format
数据一致性 Data conformance
写入元素 Writing elements
编写属性 Writing attributes
处理命名空间 Handling namespaces
写出类型化数据 Writing typed data
关闭 XML 编写器 Closing the XML writer
异步编程 Asynchronous programming
安全注意事项Security considerations

创建 XML 编写器Creating an XML writer

若要创建XmlWriter实例,请使用XmlWriter.Create方法。To create an XmlWriter instance, use the XmlWriter.Create method. 若要指定一组你想要启用对 XML 编写器的功能,请将传递XmlWriterSettingsCreate方法。To specify the set of features you want to enable on the XML writer, pass an XmlWriterSettings to the Create method. 否则,使用默认设置。Otherwise, default settings are used. 请参阅Create参考页的详细信息。See the Create reference pages for details.

指定的输出格式Specifying the output format

XmlWriterSettings类包含多个属性,用于控制如何XmlWriter输出的格式:The XmlWriterSettings class includes several properties that control how XmlWriter output is formatted:

PropertyProperty 描述Description
Encoding 指定要使用的文本编码。Specifies the text encoding to use. 默认值为 Encoding.UTF8The default is Encoding.UTF8.
Indent 指示是否使元素缩进。Indicates whether to indent elements. 默认值是false(任何缩进)。The default is false (no indentation).
IndentChars 指定在缩进时要使用的字符串。Specifies the character string to use when indenting. 默认值为两个空格。The default is two spaces.
NewLineChars 指定分行符要使用的字符串。Specifies the character string to use for line breaks. 默认值为 \r\n(回车符、换行符)。The default is \r\n (carriage return, line feed).
NewLineHandling 指定如何处理换行符。Specifies how to handle newline characters.
NewLineOnAttributes 指示是否在新行上编写属性。Indicates whether to write attributes on a new line. 在使用此属性时,Indent 应设置为 trueIndent should be set to true when using this property. 默认值为 falseThe default is false.
OmitXmlDeclaration 指示是否编写 XML 声明。Indicates whether to write an XML declaration. 默认值为 falseThe default is false.

IndentIndentChars 属性控制无效空白如何格式化。The Indent and IndentChars properties control how insignificant white space is formatted. 例如,若要缩进元素节点:For example, to indent element nodes:

XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.IndentChars = "\t";
XmlWriter writer = XmlWriter.Create("books.xml", settings);
Dim settings As New XmlWriterSettings()
settings.Indent = True
settings.IndentChars = vbTab
Dim writer As XmlWriter = XmlWriter.Create("books.xml", settings)

使用NewLineOnAttributes具有一个额外级别的缩进新行上编写每个属性:Use the NewLineOnAttributes to write each attribute on a new line with one extra level of indentation:

XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.NewLineOnAttributes = true;
XmlWriter writer = XmlWriter.Create("books.xml", settings);
Dim settings As New XmlWriterSettings()
settings.Indent = True
settings.NewLineOnAttributes = True
Dim writer As XmlWriter = XmlWriter.Create("books.xml", settings)

数据一致性Data conformance

XML 编写器使用两个属性从XmlWriterSettings类为数据一致性检查:An XML writer uses two properties from the XmlWriterSettings class to check for data conformance:

  • CheckCharacters属性指示要检查字符并抛出的 XML 编写器XmlException如果任何字符不在合法范围由 W3C 定义的异常。The CheckCharacters property instructs the XML writer to check characters and throw an XmlException exception if any characters are outside the legal range, as defined by the W3C.

  • ConformanceLevel属性配置要检查正在写入的流符合格式正确的 XML 1.0 文档或文档片段的规则由 W3C 定义的 XML 编写器。The ConformanceLevel property configures the XML writer to check that the stream being written complies with the rules for a well-formed XML 1.0 document or document fragment, as defined by the W3C. 下表所述的三个一致性级别。The three conformance levels are described in the following table. 默认值为 DocumentThe default is Document. 有关详细信息,请参阅XmlWriterSettings.ConformanceLevel属性和System.Xml.ConformanceLevel枚举。For details, see the XmlWriterSettings.ConformanceLevel property and the System.Xml.ConformanceLevel enumeration.

    级别Level 描述Description
    Document XML 输出符合格式正确的 XML 1.0 文档的规则,并可以处理由任何兼容的处理器。The XML output conforms to the rules for a well-formed XML 1.0 document and can be processed by any conforming processor.
    Fragment XML 输出符合格式正确的 XML 1.0 文档片断的规则。The XML output conforms to the rules for a well-formed XML 1.0 document fragment.
    Auto XML 编写器可以决定确认检查应用 (文档或片段) 基于传入数据的级别。The XML writer determines which level of conformation checking to apply (document or fragment) based on the incoming data.

写入元素Writing elements

可以使用以下XmlWriter编写元素节点的方法。You can use the following XmlWriter methods to write element nodes. 有关示例,请参阅所列的方法。For examples, see the methods listed.

使用Use 功能To
WriteElementString 编写整个元素节点,包括字符串值。Write an entire element node, including a string value.
WriteStartElement 若要使用多个方法调用编写元素值。To write an element value by using multiple method calls. 例如,可以调用 WriteValue 来编写类型化的值,调用 WriteCharEntity 来编写字符实体,调用 WriteAttributeString 来编写属性,也可以编写子元素。For example, you can call WriteValue to write a typed value, WriteCharEntity to write a character entity, WriteAttributeString to write an attribute, or you can write a child element. 这是更复杂的版本WriteElementString方法。This is a more sophisticated version of the WriteElementString method.

若要关闭元素,则调用WriteEndElementWriteFullEndElement方法。To close the element, you call the WriteEndElement or WriteFullEndElement method.
WriteNode 若要复制的当前位置找到的元素节点XmlReaderXPathNavigator对象。To copy an element node found at the current position of an XmlReader or XPathNavigator object. 在调用时,会将源对象中的所有内容复制到 XmlWriter 实例。When called, it copies everything from the source object to the XmlWriter instance.

编写属性Writing attributes

可以使用以下XmlWriter方法在元素节点上编写属性。You can use the following XmlWriter methods to write attributes on element nodes. 这些方法还将用于创建命名空间声明某个元素上下, 一节中所述。These methods can also be used to create namespace declarations on an element, as discussed in the next section.

使用Use 功能To
WriteAttributeString 若要编写整个属性节点,包括字符串值。To write an entire attribute node, including a string value.
WriteStartAttribute 若要编写使用多个方法调用的属性值。To write the attribute value using multiple method calls. 例如,可以调用WriteValue编写类型化的值。For example, you can call WriteValue to write a typed value. 这是更复杂的版本WriteElementString方法。This is a more sophisticated version of the WriteElementString method.

若要关闭元素,则调用WriteEndAttribute方法。To close the element, you call the WriteEndAttribute method.
WriteAttributes 若要复制的当前位置找到的所有特性XmlReader对象。To copy all the attributes found at the current position of an XmlReader object. 写入的属性取决于读取器当前所处的节点的类型:The attributes that are written depend on the type of node the reader is currently positioned on:

-对于属性节点,它将写入当前属性,然后选择属性的其余部分直到元素结束标记。- For an attribute node, it writes the current attribute, and then the rest of the attributes until the element closing tag.
-对于元素节点,它将写入包含该元素的所有属性。- For an element node, it writes all attributes contained by the element.
-对于 XML 声明节点,它将写入的所有属性声明中。- For an XML declaration node, it writes all the attributes in the declaration.
-对于所有其他节点类型,该方法将引发异常。- For all other node types, the method throws an exception.

处理命名空间Handling namespaces

命名空间用于限定 XML 文档中的元素和属性的名称。Namespaces are used to qualify element and attribute names in an XML document. Namespace 前缀将元素和属性与又与 URI 引用关联的命名空间相关联。Namespace prefixes associate elements and attributes with namespaces, which are in turn associated with URI references. 命名空间在 XML 文档中实现元素和属性名称的唯一性。Namespaces create element and attribute name uniqueness in an XML document.

XmlWriter维护对应于在当前命名空间范围内定义的所有命名空间的命名空间堆栈。The XmlWriter maintains a namespace stack that corresponds to all the namespaces defined in the current namespace scope. 在编写元素和属性时,可以通过下列方式利用命名空间:When writing elements and attributes you can utilize namespaces in the following ways:

  • 通过使用手动声明命名空间WriteAttributeString方法。Declare namespaces manually by using the WriteAttributeString method. 如果知道如何最大程度地优化命名空间声明的数目,可以使用此方法。This can be useful when you know how to best optimize the number of namespace declarations. 有关示例,请参阅WriteAttributeString(String, String, String, String)方法。For an example, see the WriteAttributeString(String, String, String, String) method.

  • 用新的命名空间重写当前命名空间声明。Override the current namespace declaration with a new namespace. 在下面的代码中,WriteAttributeString方法将更改命名空间 URI 为"x"从前缀"123""abc"In the following code, the WriteAttributeString method changes the namespace URI for the "x" prefix from "123" to "abc".

    writer.WriteStartElement("x", "root", "123");
    writer.WriteStartElement("item");
    writer.WriteAttributeString("xmlns", "x", null, "abc");
    writer.WriteEndElement();
    writer.WriteEndElement();
    
    writer.WriteStartElement("x", "root", "123")
    writer.WriteStartElement("item")
    writer.WriteAttributeString("xmlns", "x", Nothing, "abc")
    writer.WriteEndElement()
    writer.WriteEndElement()
    

    代码生成以下 XML 字符串:The code generates the following XML string:

    <x:root xmlns:x="123">  
      <item xmlns:x="abc" />  
    </x:root>  
    
  • 在编写属性或元素时指定命名空间前缀。Specify a namespace prefix when writing attributes or elements. 许多用于编写元素和属性的方法使您能够执行此操作。Many of the methods used to write element and attributes enable you to do this. 例如,WriteStartElement(String, String, String)方法写入的开始标记并将其与指定的命名空间和前缀关联起来。For example, the WriteStartElement(String, String, String) method writes a start tag and associates it with a specified namespace and prefix.

写出类型化数据Writing typed data

WriteValue方法接受公共语言运行时 (CLR) 对象、 将输入的值转换为 XML 架构定义语言 (XSD) 数据类型转换规则,根据其字符串表示形式和签出通过使用写入WriteString方法。The WriteValue method accepts a common language runtime (CLR) object, converts the input value to its string representation according to XML schema definition language (XSD) data type conversion rules, and writes it out by using the WriteString method. 这是比使用中的方法更加容易XmlConvert类写出之前将类型化的数据转换为字符串值。This is easier than using the methods in the XmlConvert class to convert the typed data to a string value before writing it out.

写入到文本时,类型化的值序列化为文本使用XmlConvert架构类型的规则。When writing to text, the typed value is serialized to text by using the XmlConvert rules for that schema type.

对应于 CLR 类型的默认 XSD 数据类型,请参阅WriteValue方法。For default XSD data types that correspond to CLR types, see the WriteValue method.

XmlWriter还可用于写入 XML 数据存储。The XmlWriter can also be used to write to an XML data store. 例如,XPathNavigator 类可以创建一个 XmlWriter 对象,用于为 XmlDocument 对象创建节点。For example, the XPathNavigator class can create an XmlWriter object to create nodes for an XmlDocument object. 如果数据存储区包含架构信息可用,WriteValue方法将引发异常,如果你尝试转换不允许的类型。如果数据存储没有架构信息,可供WriteValue方法将所有值视为xsd:anySimpleType类型。If the data store has schema information available to it, the WriteValue method throws an exception if you try to convert to a type that is not allowed.If the data store does not have schema information available to it, the WriteValue method treats all values as an xsd:anySimpleType type.

关闭 XML 编写器Closing the XML writer

当你使用XmlWriter直到您调用方法以输出 XML 中,元素和属性不会写入Close方法。When you use XmlWriter methods to output XML, the elements and attributes are not written until you call the Close method. 例如,如果使用的XmlWriter来填充XmlDocument对象,将能够看到写入的元素和目标文档中的属性,直到您关闭XmlWriter实例。For example, if you are using XmlWriter to populate an XmlDocument object, you won't be able to see the written elements and attributes in the target document until you close the XmlWriter instance.

异步编程Asynchronous programming

大多数的XmlWriter方法都具有有"Async"它们的方法名称结尾处的异步对应项。Most of the XmlWriter methods have asynchronous counterparts that have "Async" at the end of their method names. 例如,异步等效于WriteAttributeStringWriteAttributeStringAsyncFor example, the asynchronous equivalent of WriteAttributeString is WriteAttributeStringAsync.

有关WriteValue方法,它不会有异步相对应,将返回值转换为一个字符串,并使用WriteStringAsync方法相反。For the WriteValue method, which doesn't have an asynchronous counterpart, convert the return value to a string and use the WriteStringAsync method instead.

安全注意事项Security considerations

使用时,请考虑以下XmlWriter类:Consider the following when working with the XmlWriter class:

  • 引发的异常XmlWriter可能会泄露冒泡到应用程序不希望的路径信息。Exceptions thrown by the XmlWriter can disclose path information that you do not want bubbled up to the app. 您的应用程序必须捕获异常并进行相应的处理。Your app must catch exceptions and process them appropriately.

  • XmlWriter 不会验证传递到任何数据WriteDocTypeWriteRaw方法。XmlWriter does not validate any data that is passed to the WriteDocType or WriteRaw method. 不应将任意数据传递给这些方法。You should not pass arbitrary data to these methods.

构造函数

XmlWriter() XmlWriter() XmlWriter() XmlWriter()

初始化 XmlWriter 类的新实例。Initializes a new instance of the XmlWriter class.

属性

Settings Settings Settings Settings

获取用于创建此 XmlWriter 实例的 XmlWriterSettings 对象。Gets the XmlWriterSettings object used to create this XmlWriter instance.

WriteState WriteState WriteState WriteState

当在派生类中被重写时,获取写入器的状态。When overridden in a derived class, gets the state of the writer.

XmlLang XmlLang XmlLang XmlLang

当在派生类中被重写时,获取当前的 xml:lang 范围。When overridden in a derived class, gets the current xml:lang scope.

XmlSpace XmlSpace XmlSpace XmlSpace

当在派生类中被重写时,获取表示当前 xml:space 范围的 XmlSpaceWhen overridden in a derived class, gets an XmlSpace representing the current xml:space scope.

方法

Close() Close() Close() Close()

当在派生类中被重写时,将关闭此流和基础流。When overridden in a derived class, closes this stream and the underlying stream.

Create(Stream) Create(Stream) Create(Stream) Create(Stream)

使用指定的流创建一个新的 XmlWriter 实例。Creates a new XmlWriter instance using the specified stream.

Create(Stream, XmlWriterSettings) Create(Stream, XmlWriterSettings) Create(Stream, XmlWriterSettings) Create(Stream, XmlWriterSettings)

使用流和 XmlWriter 对象创建一个新的 XmlWriterSettings 实例。Creates a new XmlWriter instance using the stream and XmlWriterSettings object.

Create(String) Create(String) Create(String) Create(String)

使用指定的文件名创建一个新的 XmlWriter 实例。Creates a new XmlWriter instance using the specified filename.

Create(String, XmlWriterSettings) Create(String, XmlWriterSettings) Create(String, XmlWriterSettings) Create(String, XmlWriterSettings)

使用文件名和 XmlWriter 对象创建一个新的 XmlWriterSettings 实例。Creates a new XmlWriter instance using the filename and XmlWriterSettings object.

Create(StringBuilder) Create(StringBuilder) Create(StringBuilder) Create(StringBuilder)

使用指定的 XmlWriter 创建一个新的 StringBuilder 实例。Creates a new XmlWriter instance using the specified StringBuilder.

Create(StringBuilder, XmlWriterSettings) Create(StringBuilder, XmlWriterSettings) Create(StringBuilder, XmlWriterSettings) Create(StringBuilder, XmlWriterSettings)

使用 XmlWriterStringBuilder 对象创建一个新的 XmlWriterSettings 实例。Creates a new XmlWriter instance using the StringBuilder and XmlWriterSettings objects.

Create(TextWriter) Create(TextWriter) Create(TextWriter) Create(TextWriter)

使用指定的 XmlWriter 创建一个新的 TextWriter 实例。Creates a new XmlWriter instance using the specified TextWriter.

Create(TextWriter, XmlWriterSettings) Create(TextWriter, XmlWriterSettings) Create(TextWriter, XmlWriterSettings) Create(TextWriter, XmlWriterSettings)

使用 XmlWriterTextWriter 对象创建一个新的 XmlWriterSettings 实例。Creates a new XmlWriter instance using the TextWriter and XmlWriterSettings objects.

Create(XmlWriter) Create(XmlWriter) Create(XmlWriter) Create(XmlWriter)

使用指定的 XmlWriter 对象创建一个新的 XmlWriter 实例。Creates a new XmlWriter instance using the specified XmlWriter object.

Create(XmlWriter, XmlWriterSettings) Create(XmlWriter, XmlWriterSettings) Create(XmlWriter, XmlWriterSettings) Create(XmlWriter, XmlWriterSettings)

使用指定的 XmlWriterXmlWriter 对象创建一个新的 XmlWriterSettings 实例。Creates a new XmlWriter instance using the specified XmlWriter and XmlWriterSettings objects.

Dispose() Dispose() Dispose() Dispose()

释放 XmlWriter 类的当前实例所使用的所有资源。Releases all resources used by the current instance of the XmlWriter class.

Dispose(Boolean) Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)

释放由 XmlWriter 占用的非托管资源,还可以另外再释放托管资源。Releases the unmanaged resources used by the XmlWriter and optionally releases the managed resources.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
Flush() Flush() Flush() Flush()

当在派生类中被重写时,将缓冲区中的所有内容刷新到基础流,并同时刷新基础流。When overridden in a derived class, flushes whatever is in the buffer to the underlying streams and also flushes the underlying stream.

FlushAsync() FlushAsync() FlushAsync() FlushAsync()

将缓冲区中的所有内容异步刷新到基础流,并同时刷新基础流。Asynchronously flushes whatever is in the buffer to the underlying streams and also flushes the underlying stream.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
LookupPrefix(String) LookupPrefix(String) LookupPrefix(String) LookupPrefix(String)

当在派生类中被重写时,返回在当前命名空间范围中为该命名空间 URI 定义的最近的前缀。When overridden in a derived class, returns the closest prefix defined in the current namespace scope for the namespace URI.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)
WriteAttributes(XmlReader, Boolean) WriteAttributes(XmlReader, Boolean) WriteAttributes(XmlReader, Boolean) WriteAttributes(XmlReader, Boolean)

当在派生类中被重写时,写出在 XmlReader 中当前位置找到的所有属性。When overridden in a derived class, writes out all the attributes found at the current position in the XmlReader.

WriteAttributesAsync(XmlReader, Boolean) WriteAttributesAsync(XmlReader, Boolean) WriteAttributesAsync(XmlReader, Boolean) WriteAttributesAsync(XmlReader, Boolean)

XmlReader 中的当前位置异步写出找到的所有属性。Asynchronously writes out all the attributes found at the current position in the XmlReader.

WriteAttributeString(String, String) WriteAttributeString(String, String) WriteAttributeString(String, String) WriteAttributeString(String, String)

当在派生类中被重写时,写出具有指定的本地名称和值的属性。When overridden in a derived class, writes out the attribute with the specified local name and value.

WriteAttributeString(String, String, String) WriteAttributeString(String, String, String) WriteAttributeString(String, String, String) WriteAttributeString(String, String, String)

当在派生类中被重写时,写入具有指定的本地名称、命名空间 URI 和值的属性。When overridden in a derived class, writes an attribute with the specified local name, namespace URI, and value.

WriteAttributeString(String, String, String, String) WriteAttributeString(String, String, String, String) WriteAttributeString(String, String, String, String) WriteAttributeString(String, String, String, String)

当在派生类中被重写时,写出具有指定的前缀、本地名称、命名空间 URI 和值的属性。When overridden in a derived class, writes out the attribute with the specified prefix, local name, namespace URI, and value.

WriteAttributeStringAsync(String, String, String, String) WriteAttributeStringAsync(String, String, String, String) WriteAttributeStringAsync(String, String, String, String) WriteAttributeStringAsync(String, String, String, String)

异步写出具有指定前缀、本地名称、命名空间 URI 和值的属性。Asynchronously writes out the attribute with the specified prefix, local name, namespace URI, and value.

WriteBase64(Byte[], Int32, Int32) WriteBase64(Byte[], Int32, Int32) WriteBase64(Byte[], Int32, Int32) WriteBase64(Byte[], Int32, Int32)

当在派生类中被重写时,将指定的二进制字节编码为 Base64 并写出结果文本。When overridden in a derived class, encodes the specified binary bytes as Base64 and writes out the resulting text.

WriteBase64Async(Byte[], Int32, Int32) WriteBase64Async(Byte[], Int32, Int32) WriteBase64Async(Byte[], Int32, Int32) WriteBase64Async(Byte[], Int32, Int32)

将指定的二进制字节异步编码为 Base64 并写出结果文本。Asynchronously encodes the specified binary bytes as Base64 and writes out the resulting text.

WriteBinHex(Byte[], Int32, Int32) WriteBinHex(Byte[], Int32, Int32) WriteBinHex(Byte[], Int32, Int32) WriteBinHex(Byte[], Int32, Int32)

当在派生类中被重写时,将指定的二进制字节编码为 BinHex 并写出结果文本。When overridden in a derived class, encodes the specified binary bytes as BinHex and writes out the resulting text.

WriteBinHexAsync(Byte[], Int32, Int32) WriteBinHexAsync(Byte[], Int32, Int32) WriteBinHexAsync(Byte[], Int32, Int32) WriteBinHexAsync(Byte[], Int32, Int32)

将指定的二进制字节异步编码为 BinHex 并写出结果文本。Asynchronously encodes the specified binary bytes as BinHex and writes out the resulting text.

WriteCData(String) WriteCData(String) WriteCData(String) WriteCData(String)

当在派生类中被重写时,写出包含指定文本的 <![CDATA[...]]> 块。When overridden in a derived class, writes out a <![CDATA[...]]> block containing the specified text.

WriteCDataAsync(String) WriteCDataAsync(String) WriteCDataAsync(String) WriteCDataAsync(String)

异步写出一个包含指定文本的 <![CDATA[...]]> 块。Asynchronously writes out a <![CDATA[...]]> block containing the specified text.

WriteCharEntity(Char) WriteCharEntity(Char) WriteCharEntity(Char) WriteCharEntity(Char)

当在派生类中被重写时,为指定的 Unicode 字符值强制生成字符实体。When overridden in a derived class, forces the generation of a character entity for the specified Unicode character value.

WriteCharEntityAsync(Char) WriteCharEntityAsync(Char) WriteCharEntityAsync(Char) WriteCharEntityAsync(Char)

为指定的 Unicode 字符值异步强制生成字符实体。Asynchronously forces the generation of a character entity for the specified Unicode character value.

WriteChars(Char[], Int32, Int32) WriteChars(Char[], Int32, Int32) WriteChars(Char[], Int32, Int32) WriteChars(Char[], Int32, Int32)

当在派生类中被重写时,以每次一个缓冲区的方式写入文本。When overridden in a derived class, writes text one buffer at a time.

WriteCharsAsync(Char[], Int32, Int32) WriteCharsAsync(Char[], Int32, Int32) WriteCharsAsync(Char[], Int32, Int32) WriteCharsAsync(Char[], Int32, Int32)

以每次一个缓冲区的方式异步写入文本。Asynchronously writes text one buffer at a time.

WriteComment(String) WriteComment(String) WriteComment(String) WriteComment(String)

当在派生类中被重写时,写出包含指定文本的注释 <!--...-->。When overridden in a derived class, writes out a comment <!--...--> containing the specified text.

WriteCommentAsync(String) WriteCommentAsync(String) WriteCommentAsync(String) WriteCommentAsync(String)

异步写出一个包含指定文本的注释 <!--...-->。Asynchronously writes out a comment <!--...--> containing the specified text.

WriteDocType(String, String, String, String) WriteDocType(String, String, String, String) WriteDocType(String, String, String, String) WriteDocType(String, String, String, String)

当在派生类中被重写时,写出具有指定名称和可选属性的 DOCTYPE 声明。When overridden in a derived class, writes the DOCTYPE declaration with the specified name and optional attributes.

WriteDocTypeAsync(String, String, String, String) WriteDocTypeAsync(String, String, String, String) WriteDocTypeAsync(String, String, String, String) WriteDocTypeAsync(String, String, String, String)

异步写入具有指定名称和可选属性的 DOCTYPE 声明。Asynchronously writes the DOCTYPE declaration with the specified name and optional attributes.

WriteElementString(String, String) WriteElementString(String, String) WriteElementString(String, String) WriteElementString(String, String)

写入具有指定的本地名称和值的元素。Writes an element with the specified local name and value.

WriteElementString(String, String, String) WriteElementString(String, String, String) WriteElementString(String, String, String) WriteElementString(String, String, String)

写入具有指定的本地名称、命名空间 URI 和值的元素。Writes an element with the specified local name, namespace URI, and value.

WriteElementString(String, String, String, String) WriteElementString(String, String, String, String) WriteElementString(String, String, String, String) WriteElementString(String, String, String, String)

写入具有指定的前缀、本地名称、命名空间 URI 和值的元素。Writes an element with the specified prefix, local name, namespace URI, and value.

WriteElementStringAsync(String, String, String, String) WriteElementStringAsync(String, String, String, String) WriteElementStringAsync(String, String, String, String) WriteElementStringAsync(String, String, String, String)

异步写入具有指定的前缀、本地名称、命名空间 URI 和值的元素。Asynchronously writes an element with the specified prefix, local name, namespace URI, and value.

WriteEndAttribute() WriteEndAttribute() WriteEndAttribute() WriteEndAttribute()

当在派生类中被重写时,关闭上一个 WriteStartAttribute(String, String) 调用。When overridden in a derived class, closes the previous WriteStartAttribute(String, String) call.

WriteEndAttributeAsync() WriteEndAttributeAsync() WriteEndAttributeAsync() WriteEndAttributeAsync()

异步关闭前一个 WriteStartAttribute(String, String) 调用。Asynchronously closes the previous WriteStartAttribute(String, String) call.

WriteEndDocument() WriteEndDocument() WriteEndDocument() WriteEndDocument()

当在派生类中被重写时,关闭任何打开的元素或属性并将写入器重新设置为起始状态。When overridden in a derived class, closes any open elements or attributes and puts the writer back in the Start state.

WriteEndDocumentAsync() WriteEndDocumentAsync() WriteEndDocumentAsync() WriteEndDocumentAsync()

异步关闭任何打开的元素或属性并将写入器重新设置为起始状态。Asynchronously closes any open elements or attributes and puts the writer back in the Start state.

WriteEndElement() WriteEndElement() WriteEndElement() WriteEndElement()

当在派生类中被重写时,关闭一个元素并弹出相应的命名空间范围。When overridden in a derived class, closes one element and pops the corresponding namespace scope.

WriteEndElementAsync() WriteEndElementAsync() WriteEndElementAsync() WriteEndElementAsync()

异步关闭一个元素并弹出相应的命名空间范围。Asynchronously closes one element and pops the corresponding namespace scope.

WriteEntityRef(String) WriteEntityRef(String) WriteEntityRef(String) WriteEntityRef(String)

当在派生类中被重写时,按 &name; 写出实体引用。When overridden in a derived class, writes out an entity reference as &name;.

WriteEntityRefAsync(String) WriteEntityRefAsync(String) WriteEntityRefAsync(String) WriteEntityRefAsync(String)

&name; 异步写出实体引用。Asynchronously writes out an entity reference as &name;.

WriteFullEndElement() WriteFullEndElement() WriteFullEndElement() WriteFullEndElement()

当在派生类中被重写时,关闭一个元素并弹出相应的命名空间范围。When overridden in a derived class, closes one element and pops the corresponding namespace scope.

WriteFullEndElementAsync() WriteFullEndElementAsync() WriteFullEndElementAsync() WriteFullEndElementAsync()

异步关闭一个元素并弹出相应的命名空间范围。Asynchronously closes one element and pops the corresponding namespace scope.

WriteName(String) WriteName(String) WriteName(String) WriteName(String)

当在派生类中被重写时,写出指定的名称,确保它是符合 W3C XML 1.0 建议 (https://www.w3.org/TR/1998/REC-xml-19980210#NT-Name)) 的有效名称。When overridden in a derived class, writes out the specified name, ensuring it is a valid name according to the W3C XML 1.0 recommendation (https://www.w3.org/TR/1998/REC-xml-19980210#NT-Name).

WriteNameAsync(String) WriteNameAsync(String) WriteNameAsync(String) WriteNameAsync(String)

异步写出指定的名称,确保它是符合 W3C XML 1.0 建议 (https://www.w3.org/TR/1998/REC-xml-19980210#NT-Name)) 的有效名称。Asynchronously writes out the specified name, ensuring it is a valid name according to the W3C XML 1.0 recommendation (https://www.w3.org/TR/1998/REC-xml-19980210#NT-Name).

WriteNmToken(String) WriteNmToken(String) WriteNmToken(String) WriteNmToken(String)

当在派生类中被重写时,写出指定的名称,确保它是符合 W3C XML 1.0 建议 (https://www.w3.org/TR/1998/REC-xml-19980210#NT-Name)) 的有效 NmToken。When overridden in a derived class, writes out the specified name, ensuring it is a valid NmToken according to the W3C XML 1.0 recommendation (https://www.w3.org/TR/1998/REC-xml-19980210#NT-Name).

WriteNmTokenAsync(String) WriteNmTokenAsync(String) WriteNmTokenAsync(String) WriteNmTokenAsync(String)

异步写出指定的名称,确保它是符合 W3C XML 1.0 建议 (https://www.w3.org/TR/1998/REC-xml-19980210#NT-Name)) 的有效 NmToken。Asynchronously writes out the specified name, ensuring it is a valid NmToken according to the W3C XML 1.0 recommendation (https://www.w3.org/TR/1998/REC-xml-19980210#NT-Name).

WriteNode(XmlReader, Boolean) WriteNode(XmlReader, Boolean) WriteNode(XmlReader, Boolean) WriteNode(XmlReader, Boolean)

当在派生类中被重写时,将全部内容从读取器复制到写入器并将读取器移动到下一个同级的开始位置。When overridden in a derived class, copies everything from the reader to the writer and moves the reader to the start of the next sibling.

WriteNode(XPathNavigator, Boolean) WriteNode(XPathNavigator, Boolean) WriteNode(XPathNavigator, Boolean) WriteNode(XPathNavigator, Boolean)

将所有内容从 XPathNavigator 对象复制到编写器。Copies everything from the XPathNavigator object to the writer. XPathNavigator 的位置保持不变。The position of the XPathNavigator remains unchanged.

WriteNodeAsync(XmlReader, Boolean) WriteNodeAsync(XmlReader, Boolean) WriteNodeAsync(XmlReader, Boolean) WriteNodeAsync(XmlReader, Boolean)

将所有内容从读取器异步复制到写入器并将读取器移动到下一个同级的开头。Asynchronously copies everything from the reader to the writer and moves the reader to the start of the next sibling.

WriteNodeAsync(XPathNavigator, Boolean) WriteNodeAsync(XPathNavigator, Boolean) WriteNodeAsync(XPathNavigator, Boolean) WriteNodeAsync(XPathNavigator, Boolean)

从编写器的 XPathNavigator 对象中异步复制所有内容。Asynchronously copies everything from the XPathNavigator object to the writer. XPathNavigator 的位置保持不变。The position of the XPathNavigator remains unchanged.

WriteProcessingInstruction(String, String) WriteProcessingInstruction(String, String) WriteProcessingInstruction(String, String) WriteProcessingInstruction(String, String)

当在派生类中被重写时,写出在名称和文本之间带有空格的处理指令,如下所示:<?name text?>。When overridden in a derived class, writes out a processing instruction with a space between the name and text as follows: <?name text?>.

WriteProcessingInstructionAsync(String, String) WriteProcessingInstructionAsync(String, String) WriteProcessingInstructionAsync(String, String) WriteProcessingInstructionAsync(String, String)

异步写出在名称和文本之间有空格的处理指令,如下所示:<?name text?>。Asynchronously writes out a processing instruction with a space between the name and text as follows: <?name text?>.

WriteQualifiedName(String, String) WriteQualifiedName(String, String) WriteQualifiedName(String, String) WriteQualifiedName(String, String)

当在派生类中被重写时,写出命名空间限定的名称。When overridden in a derived class, writes out the namespace-qualified name. 此方法查找位于给定命名空间范围内的前缀。This method looks up the prefix that is in scope for the given namespace.

WriteQualifiedNameAsync(String, String) WriteQualifiedNameAsync(String, String) WriteQualifiedNameAsync(String, String) WriteQualifiedNameAsync(String, String)

异步写出命名空间限定的名称。Asynchronously writes out the namespace-qualified name. 此方法查找位于给定命名空间范围内的前缀。This method looks up the prefix that is in scope for the given namespace.

WriteRaw(Char[], Int32, Int32) WriteRaw(Char[], Int32, Int32) WriteRaw(Char[], Int32, Int32) WriteRaw(Char[], Int32, Int32)

当在派生类中被重写时,从字符缓冲区手动写入原始标记。When overridden in a derived class, writes raw markup manually from a character buffer.

WriteRaw(String) WriteRaw(String) WriteRaw(String) WriteRaw(String)

当在派生类中被重写时,从字符串手动写入原始标记。When overridden in a derived class, writes raw markup manually from a string.

WriteRawAsync(Char[], Int32, Int32) WriteRawAsync(Char[], Int32, Int32) WriteRawAsync(Char[], Int32, Int32) WriteRawAsync(Char[], Int32, Int32)

从字符缓冲区手动异步写入原始标记。Asynchronously writes raw markup manually from a character buffer.

WriteRawAsync(String) WriteRawAsync(String) WriteRawAsync(String) WriteRawAsync(String)

从字符串手动异步写入原始标记。Asynchronously writes raw markup manually from a string.

WriteStartAttribute(String) WriteStartAttribute(String) WriteStartAttribute(String) WriteStartAttribute(String)

写入具有指定本地名称的属性的开头。Writes the start of an attribute with the specified local name.

WriteStartAttribute(String, String) WriteStartAttribute(String, String) WriteStartAttribute(String, String) WriteStartAttribute(String, String)

写入具有指定本地名称和命名空间 URI 的属性的开头。Writes the start of an attribute with the specified local name and namespace URI.

WriteStartAttribute(String, String, String) WriteStartAttribute(String, String, String) WriteStartAttribute(String, String, String) WriteStartAttribute(String, String, String)

当在派生类中被重写时,写入具有指定的前缀、本地名称和命名空间 URI 的属性的开头。When overridden in a derived class, writes the start of an attribute with the specified prefix, local name, and namespace URI.

WriteStartAttributeAsync(String, String, String) WriteStartAttributeAsync(String, String, String) WriteStartAttributeAsync(String, String, String) WriteStartAttributeAsync(String, String, String)

异步写入具有指定前缀、本地名称和命名空间 URI 的属性的开头。Asynchronously writes the start of an attribute with the specified prefix, local name, and namespace URI.

WriteStartDocument() WriteStartDocument() WriteStartDocument() WriteStartDocument()

当在派生类中被重写时,写入版本为“1.0”的 XML 声明。When overridden in a derived class, writes the XML declaration with the version "1.0".

WriteStartDocument(Boolean) WriteStartDocument(Boolean) WriteStartDocument(Boolean) WriteStartDocument(Boolean)

当在派生类中被重写时,写入版本为“1.0”的 XML 声明和独立的属性。When overridden in a derived class, writes the XML declaration with the version "1.0" and the standalone attribute.

WriteStartDocumentAsync() WriteStartDocumentAsync() WriteStartDocumentAsync() WriteStartDocumentAsync()

异步写入版本为“1.0”的 XML 声明。Asynchronously writes the XML declaration with the version "1.0".

WriteStartDocumentAsync(Boolean) WriteStartDocumentAsync(Boolean) WriteStartDocumentAsync(Boolean) WriteStartDocumentAsync(Boolean)

异步写入版本为“1.0”的 XML 声明和独立的属性。Asynchronously writes the XML declaration with the version "1.0" and the standalone attribute.

WriteStartElement(String) WriteStartElement(String) WriteStartElement(String) WriteStartElement(String)

当在派生类中被重写时,写出具有指定的本地名称的开始标记。When overridden in a derived class, writes out a start tag with the specified local name.

WriteStartElement(String, String) WriteStartElement(String, String) WriteStartElement(String, String) WriteStartElement(String, String)

当在派生类中被重写时,写入指定的开始标记并将其与给定的命名空间关联起来。When overridden in a derived class, writes the specified start tag and associates it with the given namespace.

WriteStartElement(String, String, String) WriteStartElement(String, String, String) WriteStartElement(String, String, String) WriteStartElement(String, String, String)

当在派生类中被重写时,写入指定的开始标记并将其与给定的命名空间和前缀关联起来。When overridden in a derived class, writes the specified start tag and associates it with the given namespace and prefix.

WriteStartElementAsync(String, String, String) WriteStartElementAsync(String, String, String) WriteStartElementAsync(String, String, String) WriteStartElementAsync(String, String, String)

异步写入指定的开始标记并将其与给定的命名空间和前缀关联起来。Asynchronously writes the specified start tag and associates it with the given namespace and prefix.

WriteString(String) WriteString(String) WriteString(String) WriteString(String)

当在派生类中被重写时,写入给定的文本内容。When overridden in a derived class, writes the given text content.

WriteStringAsync(String) WriteStringAsync(String) WriteStringAsync(String) WriteStringAsync(String)

异步写入给定的文本内容。Asynchronously writes the given text content.

WriteSurrogateCharEntity(Char, Char) WriteSurrogateCharEntity(Char, Char) WriteSurrogateCharEntity(Char, Char) WriteSurrogateCharEntity(Char, Char)

当在派生类中被重写时,为代理项字符对生成并写入代理项字符实体。When overridden in a derived class, generates and writes the surrogate character entity for the surrogate character pair.

WriteSurrogateCharEntityAsync(Char, Char) WriteSurrogateCharEntityAsync(Char, Char) WriteSurrogateCharEntityAsync(Char, Char) WriteSurrogateCharEntityAsync(Char, Char)

为代理项字符对异步生成并写入代理项字符实体。Asynchronously generates and writes the surrogate character entity for the surrogate character pair.

WriteValue(Boolean) WriteValue(Boolean) WriteValue(Boolean) WriteValue(Boolean)

写入 Boolean 值。Writes a Boolean value.

WriteValue(DateTime) WriteValue(DateTime) WriteValue(DateTime) WriteValue(DateTime)

写入 DateTime 值。Writes a DateTime value.

WriteValue(DateTimeOffset) WriteValue(DateTimeOffset) WriteValue(DateTimeOffset) WriteValue(DateTimeOffset)

写入 DateTimeOffset 值。Writes a DateTimeOffset value.

WriteValue(Decimal) WriteValue(Decimal) WriteValue(Decimal) WriteValue(Decimal)

写入 Decimal 值。Writes a Decimal value.

WriteValue(Double) WriteValue(Double) WriteValue(Double) WriteValue(Double)

写入 Double 值。Writes a Double value.

WriteValue(Int32) WriteValue(Int32) WriteValue(Int32) WriteValue(Int32)

写入 Int32 值。Writes a Int32 value.

WriteValue(Int64) WriteValue(Int64) WriteValue(Int64) WriteValue(Int64)

写入 Int64 值。Writes a Int64 value.

WriteValue(Object) WriteValue(Object) WriteValue(Object) WriteValue(Object)

写入对象值。Writes the object value.

WriteValue(Single) WriteValue(Single) WriteValue(Single) WriteValue(Single)

写入一个单精度浮点数。Writes a single-precision floating-point number.

WriteValue(String) WriteValue(String) WriteValue(String) WriteValue(String)

写入 String 值。Writes a String value.

WriteWhitespace(String) WriteWhitespace(String) WriteWhitespace(String) WriteWhitespace(String)

当在派生类中被重写时,写出给定的空白区域。When overridden in a derived class, writes out the given white space.

WriteWhitespaceAsync(String) WriteWhitespaceAsync(String) WriteWhitespaceAsync(String) WriteWhitespaceAsync(String)

异步写出给定的空白区域。Asynchronously writes out the given white space.

显式界面实现

IDisposable.Dispose() IDisposable.Dispose() IDisposable.Dispose() IDisposable.Dispose()

有关此成员的说明,请参见 Dispose()For a description of this member, see Dispose().

适用于

另请参阅