XmlWriter XmlWriter XmlWriter XmlWriter Class

Definition

表示寫入器,其可提供快速、非快取的順向方法來產生含有 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
Inheritance
XmlWriterXmlWriterXmlWriterXmlWriter
Derived
Implements

Examples

下列程式碼範例示範如何使用非同步 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();  
    }  
}  

Remarks

XmlWriter類別會將 XML 資料寫入至資料流、 檔案、 文字讀取器或字串。The XmlWriter class writes XML data to a stream, file, text reader, or string. 它支援 W3C可延伸標記語言 (XML) 1.0 (第四版)Namespaces in 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.

  • 若要避免以手動方式執行值的轉換,而不是字串,使用 common language runtime 類型傳遞值。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:

屬性Property 描述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. 命名空間前置詞相關聯的命名空間,依序相關聯的 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方法會接受的 common language runtime (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.

預設 XSD 資料型別對應至 CLR 型別,請參閱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.

Constructors

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

初始化 XmlWriter 類別的新執行個體。 Initializes a new instance of the XmlWriter class.

Properties

Settings Settings Settings Settings

取得 XmlWriterSettings 物件,用於建立這個 XmlWriter 執行個體。 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 範圍的 XmlSpace When overridden in a derived class, gets an XmlSpace representing the current xml:space scope.

Methods

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 所使用的 Unmanaged 資源,並選擇性地釋放 Managed 資源。 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()

取得目前執行個體的 Type Gets 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 的淺層複本 (Shallow Copy)。 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 建議 (http://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 (http://www.w3.org/TR/1998/REC-xml-19980210#NT-Name).

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

非同步地寫出指定的名稱,以確保它是符合 W3C XML 1.0 建議 (http://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 (http://www.w3.org/TR/1998/REC-xml-19980210#NT-Name).

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

當覆寫衍生類別時,請寫出指定的名稱,以確保它是符合 W3C XML 1.0 建議 (http://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 (http://www.w3.org/TR/1998/REC-xml-19980210#NT-Name).

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

非同步地寫出指定的名稱,以確保它是符合 W3C XML 1.0 建議 (http://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 (http://www.w3.org/TR/1998/REC-xml-19980210#NT-Name).

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

在衍生類別中覆寫時,從讀取器複製所有內容至寫入器,並將讀取器移至下一個同層級 (Sibling) 的開頭。 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)

以非同步的方式從讀取器複製所有內容至寫入器,並將讀取器移至下一個同層級 (Sibling) 的開頭。 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)

在衍生類別中覆寫時,從字串手動寫入未經處理的標記 (Raw Markup)。 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)

以非同步的方式從字串手動寫入未經處理的標記 (Raw Markup)。 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)

在衍生類別中覆寫時,產生和寫入 Surrogate 字元字組的 Surrogate 字元實體。 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)

以非同步的方式產生和寫入 Surrogate 字元字組的 Surrogate 字元實體。 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.

Explicit Interface Implementations

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

如需這個成員的說明,請參閱 Dispose() For a description of this member, see Dispose().

Applies to

See Also