XmlWriter 類別

定義

表示寫入器,其可提供快速、非快取的順向方法來產生含有 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
繼承
XmlWriter
衍生
實作

範例

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

  • 使用 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 寫入器上啟用的一組功能, XmlWriterSettings請將Create傳遞至方法。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. 如需詳細資訊,請參閱參考頁面。CreateSee the Create reference pages for details.

指定輸出格式Specifying the output format

類別包含數個屬性,可控制輸出的格式化方式XmlWriterXmlWriterSettingsThe 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:

  • 屬性會指示 XML 寫入器檢查字元,並在合法XmlException範圍以外的任何字元(如 W3C 所定義)時擲回例外狀況。 CheckCharactersThe 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 寫入器,以檢查所撰寫的資料流程是否符合格式正確之 XML 1.0 檔或檔片段的規則,如 W3C 所定義。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方法會將"x"前置詞的命名空間 URI "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

方法會接受 common language runtime (CLR)物件,根據 XML 架構定義語言(XSD)資料類型轉換規則,將輸入值轉換為其字串表示,並WriteString使用方法將其寫出。 WriteValueThe 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. 例如,如果您使用XmlWriterXmlDocument填入物件,則在關閉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. 例如,的非同步對等WriteAttributeString是。 WriteAttributeStringAsyncFor example, the asynchronous equivalent of WriteAttributeString is WriteAttributeStringAsync.

針對沒有非同步對應的WriteStringAsync 方法,將傳回值轉換為字串,並改用方法。WriteValueFor 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 類別的新執行個體。Initializes a new instance of the XmlWriter class.

屬性

Settings

取得 XmlWriterSettings 物件,用於建立這個 XmlWriter 執行個體。Gets the XmlWriterSettings object used to create this XmlWriter instance.

WriteState

在衍生類別中覆寫時,取得寫入器的狀態。When overridden in a derived class, gets the state of the writer.

XmlLang

當在衍生類別中覆寫時,取得目前xml:lang範圍。When overridden in a derived class, gets the current xml:lang scope.

XmlSpace

在衍生類別中覆寫時,取得表示目前 xml:space 範圍的 XmlSpaceWhen overridden in a derived class, gets an XmlSpace representing the current xml:space scope.

方法

Close()

在衍生類別中覆寫時,關閉這個資料流和基礎資料流。When overridden in a derived class, closes this stream and the underlying stream.

Create(Stream)

使用指定的資料流,建立新的 XmlWriter 執行個體。Creates a new XmlWriter instance using the specified stream.

Create(Stream, XmlWriterSettings)

使用資料流和 XmlWriter 物件,建立新 XmlWriterSettings 執行個體。Creates a new XmlWriter instance using the stream and XmlWriterSettings object.

Create(String)

使用指定的檔名,建立新 XmlWriter 執行個體。Creates a new XmlWriter instance using the specified filename.

Create(String, XmlWriterSettings)

使用檔名和 XmlWriter 物件,建立新 XmlWriterSettings 執行個體。Creates a new XmlWriter instance using the filename and XmlWriterSettings object.

Create(StringBuilder)

使用指定的 XmlWriter,建立新 StringBuilder 執行個體。Creates a new XmlWriter instance using the specified StringBuilder.

Create(StringBuilder, XmlWriterSettings)

使用 XmlWriterStringBuilder 物件,建立新的 XmlWriterSettings 執行個體。Creates a new XmlWriter instance using the StringBuilder and XmlWriterSettings objects.

Create(TextWriter)

使用指定的 XmlWriter,建立新 TextWriter 執行個體。Creates a new XmlWriter instance using the specified TextWriter.

Create(TextWriter, XmlWriterSettings)

使用 XmlWriterTextWriter 物件,建立新的 XmlWriterSettings 執行個體。Creates a new XmlWriter instance using the TextWriter and XmlWriterSettings objects.

Create(XmlWriter)

使用指定的 XmlWriter 物件,建立新 XmlWriter 執行個體。Creates a new XmlWriter instance using the specified XmlWriter object.

Create(XmlWriter, XmlWriterSettings)

使用指定的 XmlWriterXmlWriter 物件,建立新的 XmlWriterSettings 執行個體。Creates a new XmlWriter instance using the specified XmlWriter and XmlWriterSettings objects.

Dispose()

釋放 XmlWriter 類別目前的執行個體所使用的全部資源。Releases all resources used by the current instance of the XmlWriter class.

Dispose(Boolean)

釋放 XmlWriter 所使用的 Unmanaged 資源,並選擇性地釋放 Managed 資源。Releases the unmanaged resources used by the XmlWriter and optionally releases the managed resources.

Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
Flush()

在衍生類別中覆寫時,將緩衝區的所有內容清空至基礎資料流,然後清空基礎資料流。When overridden in a derived class, flushes whatever is in the buffer to the underlying streams and also flushes the underlying stream.

FlushAsync()

以非同步的方式將緩衝區的所有內容清空至基礎資料流,然後清空基礎資料流。Asynchronously flushes whatever is in the buffer to the underlying streams and also flushes the underlying stream.

GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)
GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
LookupPrefix(String)

在衍生類別中覆寫時,傳回最接近命名空間 URI 在目前命名空間範圍中定義的前置詞。When overridden in a derived class, returns the closest prefix defined in the current namespace scope for the namespace URI.

MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)
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)

非同步寫出在 XmlReader 中的目前位置找到的所有屬性。Asynchronously writes out all the attributes found at the current position in the XmlReader.

WriteAttributeString(String, String)

在衍生類別中覆寫時,寫出具有指定的區域名稱與數值的屬性。When overridden in a derived class, writes out the attribute with the specified local name and value.

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)

在衍生類別中覆寫時,寫出具有指定的前置詞、區域名稱、命名空間 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)

以非同步的方式寫出具有指定之前置詞、區域名稱、命名空間 URI 和值的屬性。Asynchronously writes out the attribute with the specified prefix, local name, namespace URI, and value.

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)

以非同步的方式將指定的二進位位元組編碼為 base64 並寫出產生的文字。Asynchronously encodes the specified binary bytes as Base64 and writes out the resulting text.

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)

以非同步的方式將指定的二進位位元組編碼為 BinHex 並寫出產生的文字。Asynchronously encodes the specified binary bytes as BinHex and writes out the resulting text.

WriteCData(String)

在衍生類別中覆寫時,寫出包含指定文字的 <![CDATA[...]]> 區塊。When overridden in a derived class, writes out a <![CDATA[...]]> block containing the specified text.

WriteCDataAsync(String)

以非同步的方式寫出包含指定文字的 <![CDATA[...]]> 區塊。Asynchronously writes out a <![CDATA[...]]> block containing the specified text.

WriteCharEntity(Char)

在衍生類別中覆寫時,強制產生指定之 Unicode 字元值的字元實體。When overridden in a derived class, forces the generation of a character entity for the specified Unicode character value.

WriteCharEntityAsync(Char)

以非同步的方式強制產生指定的 Unicode 字元值的字元實體。Asynchronously forces the generation of a character entity for the specified Unicode character value.

WriteChars(Char[], Int32, Int32)

在衍生類別中覆寫時,一次將文字寫入一個緩衝區。When overridden in a derived class, writes text one buffer at a time.

WriteCharsAsync(Char[], Int32, Int32)

以非同步的方式一次將文字寫入一個緩衝區。Asynchronously writes text one buffer at a time.

WriteComment(String)

在衍生類別中覆寫時,寫出包含指定文字的註解 <!--...-->。When overridden in a derived class, writes out a comment <!--...--> containing the specified text.

WriteCommentAsync(String)

以非同步的方式寫出包含指定文字的註解 <!--...-->。Asynchronously writes out a comment <!--...--> containing the specified text.

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)

以非同步的方式寫入具有指定名稱與選擇性屬性的 DOCTYPE 宣告。Asynchronously writes the DOCTYPE declaration with the specified name and optional attributes.

WriteElementString(String, String)

寫入具有指定之區域名稱和值的項目。Writes an element with the specified local name and value.

WriteElementString(String, String, String)

寫入具有指定之區域名稱、命名空間 URI 和值的項目。Writes an element with the specified local name, namespace URI, and value.

WriteElementString(String, String, String, String)

寫入具有指定的前置詞、區域名稱、命名空間 URI 和值的項目。Writes an element with the specified prefix, local name, namespace URI, and value.

WriteElementStringAsync(String, String, String, String)

以非同步的方式寫入具有指定之前置詞、區域名稱、命名空間 URI 和值的項目。Asynchronously writes an element with the specified prefix, local name, namespace URI, and value.

WriteEndAttribute()

在衍生類別中覆寫時,會關閉先前的 WriteStartAttribute(String, String) 呼叫。When overridden in a derived class, closes the previous WriteStartAttribute(String, String) call.

WriteEndAttributeAsync()

非同步關閉上一個 WriteStartAttribute(String, String) 呼叫。Asynchronously closes the previous WriteStartAttribute(String, String) call.

WriteEndDocument()

在衍生類別中覆寫時,關閉任何開啟的項目或屬性,並將寫入器回復開始狀態。When overridden in a derived class, closes any open elements or attributes and puts the writer back in the Start state.

WriteEndDocumentAsync()

以非同步的方式關閉任何開啟的項目或屬性,並將寫入器回復開始狀態。Asynchronously closes any open elements or attributes and puts the writer back in the Start state.

WriteEndElement()

在衍生類別中覆寫時,關閉一個項目並取出對應的命名空間範圍。When overridden in a derived class, closes one element and pops the corresponding namespace scope.

WriteEndElementAsync()

以非同步的方式關閉一個項目並取出對應的命名空間範圍。Asynchronously closes one element and pops the corresponding namespace scope.

WriteEntityRef(String)

在衍生類別中覆寫時,寫出如 &name; 的實體參考。When overridden in a derived class, writes out an entity reference as &name;.

WriteEntityRefAsync(String)

以非同步的方式將實體參考寫出為 &name;Asynchronously writes out an entity reference as &name;.

WriteFullEndElement()

在衍生類別中覆寫時,關閉一個項目並取出對應的命名空間範圍。When overridden in a derived class, closes one element and pops the corresponding namespace scope.

WriteFullEndElementAsync()

以非同步的方式關閉一個項目並取出對應的命名空間範圍。Asynchronously closes one element and pops the corresponding namespace scope.

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)

非同步地寫出指定的名稱,以確保它是符合 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)

當覆寫衍生類別時,請寫出指定的名稱,以確保它是符合 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)

非同步地寫出指定的名稱,以確保它是符合 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)

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

XPathNavigator 物件中的所有項目複製到寫入器。Copies everything from the XPathNavigator object to the writer. XPathNavigator 的位置保持不變。The position of the XPathNavigator remains unchanged.

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)

以非同步方式將所有項目從 XPathNavigator 物件複製到寫入器。Asynchronously copies everything from the XPathNavigator object to the writer. XPathNavigator 的位置保持不變。The position of the XPathNavigator remains unchanged.

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)

以非同步方式寫出名稱與文字之間有空白的處理指示,如下所示:<?name text?>。Asynchronously writes out a processing instruction with a space between the name and text as follows: <?name text?>.

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)

以非同步的方式寫出命名空間限定名稱。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)

在衍生類別中覆寫時,從字元緩衝區手動寫入未經處理的標記。When overridden in a derived class, writes raw markup manually from a character buffer.

WriteRaw(String)

在衍生類別中覆寫時,從字串手動寫入未經處理的標記 (Raw Markup)。When overridden in a derived class, writes raw markup manually from a string.

WriteRawAsync(Char[], Int32, Int32)

以非同步的方式從字元緩衝區手動寫入未經處理的標記。Asynchronously writes raw markup manually from a character buffer.

WriteRawAsync(String)

以非同步的方式從字串手動寫入未經處理的標記 (Raw Markup)。Asynchronously writes raw markup manually from a string.

WriteStartAttribute(String)

寫入具有指定之區域名稱的屬性開頭。Writes the start of an attribute with the specified local name.

WriteStartAttribute(String, String)

寫入具有指定之區域名稱和命名空間 URI 之屬性的開頭。Writes the start of an attribute with the specified local name and namespace URI.

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)

以非同步的方式寫入具有指定之前置詞、本機名稱和命名空間 URI 之屬性的開頭。Asynchronously writes the start of an attribute with the specified prefix, local name, and namespace URI.

WriteStartDocument()

在衍生類別中覆寫時,使用「1.0」版寫入 XML 宣告。When overridden in a derived class, writes the XML declaration with the version "1.0".

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()

以非同步的方式使用「1.0」版寫入 XML 宣告。Asynchronously writes the XML declaration with the version "1.0".

WriteStartDocumentAsync(Boolean)

以非同步的方式使用「1.0」版寫入 XML 宣告與獨立屬性。Asynchronously writes the XML declaration with the version "1.0" and the standalone attribute.

WriteStartElement(String)

在衍生類別中覆寫時,寫出具有指定之區域名稱的開頭標記。When overridden in a derived class, writes out a start tag with the specified local name.

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)

在衍生類別中覆寫時,寫入指定的開頭標記,並與指定的命名空間與前置詞產生關聯。When overridden in a derived class, writes the specified start tag and associates it with the given namespace and prefix.

WriteStartElementAsync(String, String, String)

以非同步的方式寫入指定的開頭標記,並將它與指定的命名空間與前置詞產生關聯。Asynchronously writes the specified start tag and associates it with the given namespace and prefix.

WriteString(String)

在衍生類別中覆寫時,寫入指定的文字內容。When overridden in a derived class, writes the given text content.

WriteStringAsync(String)

以非同步的方式寫入指定的文字內容。Asynchronously writes the given text content.

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)

以非同步的方式產生和寫入 Surrogate 字元字組的 Surrogate 字元實體。Asynchronously generates and writes the surrogate character entity for the surrogate character pair.

WriteValue(Boolean)

寫入 Boolean 值。Writes a Boolean value.

WriteValue(DateTime)

寫入 DateTime 值。Writes a DateTime value.

WriteValue(DateTimeOffset)

寫入 DateTimeOffset 值。Writes a DateTimeOffset value.

WriteValue(Decimal)

寫入 Decimal 值。Writes a Decimal value.

WriteValue(Double)

寫入 Double 值。Writes a Double value.

WriteValue(Int32)

寫入 Int32 值。Writes a Int32 value.

WriteValue(Int64)

寫入 Int64 值。Writes a Int64 value.

WriteValue(Object)

寫入物件值。Writes the object value.

WriteValue(Single)

寫入單精確度浮點數。Writes a single-precision floating-point number.

WriteValue(String)

寫入 String 值。Writes a String value.

WriteWhitespace(String)

在衍生類別中覆寫時,寫出指定的空白字元。When overridden in a derived class, writes out the given white space.

WriteWhitespaceAsync(String)

以非同步的方式寫出指定的空白字元。Asynchronously writes out the given white space.

明確介面實作

IDisposable.Dispose()

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

適用於

另請參閱