XmlWriter.WriteStartDocument XmlWriter.WriteStartDocument XmlWriter.WriteStartDocument XmlWriter.WriteStartDocument Method

定義

在衍生類別中覆寫時,寫入 XML 宣告。When overridden in a derived class, writes the XML declaration.

多載

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參閱。For the asynchronous version of this method, see WriteStartDocumentAsync.

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

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

public:
 abstract void WriteStartDocument();
public abstract void WriteStartDocument ();
abstract member WriteStartDocument : unit -> unit
Public MustOverride Sub WriteStartDocument ()

例外狀況

這不是在建構函式之後呼叫的第一個寫入方法。This is not the first write method called after the constructor.

-或--or-

在先前的非同步作業完成前呼叫了 XmlWriter 方法。An XmlWriter method was called before a previous asynchronous operation finished. 在此情況下,會擲回 InvalidOperationException 與「非同步作業已經在進行中」的訊息。In this case, InvalidOperationException is thrown with the message "An asynchronous operation is already in progress."

備註

檔的編碼層級是由寫入器的實作為來決定。The encoding level of the document is determined by how the writer is implemented. 例如,如果在此Encoding函式XmlTextWriter中指定了物件,這會決定編碼屬性的值。For example, if an Encoding object is specified in the XmlTextWriter constructor, this determines the value of the encoding attribute. 這個方法不會建立獨立的屬性。This method does not create a standalone attribute.

WriteStartDocument呼叫時,寫入器會驗證您要撰寫的內容是格式正確的 XML 檔。When WriteStartDocument is called the writer validates that what you are writing is a well-formed XML document. 例如,它會檢查 XML 宣告是否為第一個節點、只有一個根層級元素存在,依此類推。For example, it checks that the XML declaration is the first node, that one and only one root-level element exists, and so on. 如果未呼叫此方法,寫入器會假設正在寫入 XML 片段,而且不會套用根層級規則。If this method is not called, the writer assumes an XML fragment is being written and applies no root level rules.

如果WriteStartDocument已呼叫, WriteProcessingInstruction然後使用方法來建立另一個 XML 宣告,將會擲回例外狀況。If WriteStartDocument has been called and then the WriteProcessingInstruction method is used to create another XML declaration, an exception will be thrown.

如需這個方法的非同步版本,請WriteStartDocumentAsync參閱。For the asynchronous version of this method, see WriteStartDocumentAsync.

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.

public:
 abstract void WriteStartDocument(bool standalone);
public abstract void WriteStartDocument (bool standalone);
abstract member WriteStartDocument : bool -> unit
Public MustOverride Sub WriteStartDocument (standalone As Boolean)

參數

standalone
Boolean Boolean Boolean Boolean

如果 true,它會寫入「standalone=yes」;如果 false,它會寫入「standalone=no」。If true, it writes "standalone=yes"; if false, it writes "standalone=no".

例外狀況

這不是在建構函式之後呼叫的第一個寫入方法。This is not the first write method called after the constructor.

-或--or-

在先前的非同步作業完成前呼叫了 XmlWriter 方法。An XmlWriter method was called before a previous asynchronous operation finished. 在此情況下,會擲回 InvalidOperationException 與「非同步作業已經在進行中」的訊息。In this case, InvalidOperationException is thrown with the message "An asynchronous operation is already in progress."

備註

檔的編碼層級是由寫入器的實作為來決定。The encoding level of the document is determined by how the writer is implemented. 例如,如果在此Encoding函式XmlTextWriter中指定了物件,這會決定編碼屬性的值。For example, if an Encoding object is specified in the XmlTextWriter constructor, this determines the value of the encoding attribute.

WriteStartDocument呼叫時,寫入器會驗證您所撰寫的內容是否為格式正確的 XML 檔。When WriteStartDocument is called, the writer validates that what you are writing is a well-formed XML document. 例如,它會檢查 XML 宣告是否為第一個節點、只有一個根層級元素存在,依此類推。For example, it checks that the XML declaration is the first node, that one and only one root-level element exists, and so on. 如果未呼叫此方法,寫入器會假設正在寫入 XML 片段,而且不會套用根層級規則。If this method is not called, the writer assumes an XML fragment is being written and applies no root level rules.

如果WriteStartDocument已呼叫, WriteProcessingInstruction然後使用方法來建立另一個 XML 宣告,將會擲回例外狀況。If WriteStartDocument has been called and then the WriteProcessingInstruction method is used to create another XML declaration, an exception will be thrown.

如需這個方法的非同步版本,請WriteStartDocumentAsync參閱。For the asynchronous version of this method, see WriteStartDocumentAsync.

適用於