XmlWriterSettings.NewLineHandling XmlWriterSettings.NewLineHandling XmlWriterSettings.NewLineHandling XmlWriterSettings.NewLineHandling Property

定義

取得或設定值,指出是否要將輸出中的分行符號正規化。Gets or sets a value indicating whether to normalize line breaks in the output.

public:
 property System::Xml::NewLineHandling NewLineHandling { System::Xml::NewLineHandling get(); void set(System::Xml::NewLineHandling value); };
public System.Xml.NewLineHandling NewLineHandling { get; set; }
member this.NewLineHandling : System.Xml.NewLineHandling with get, set
Public Property NewLineHandling As NewLineHandling

屬性值

其中一個 NewLineHandling 值。One of the NewLineHandling values. 預設為 ReplaceThe default is Replace.

備註

寫入文字內容或屬性的值時,會套用此設定。This setting applies when writing text content or attribute values. 每個NewLineHandling值如下所述:Each of the NewLineHandling values is described below:

  • Entitize設定會告知XmlWriter取代新行字元,就不會否則保留正規化XmlReader字元實體。The Entitize setting tells the XmlWriter to replace new line characters that would not be otherwise preserved by a normalizing XmlReader with character entities. 這是用於輸出由正規化的反覆存取案例XmlReaderThis is useful in round-trip scenarios where the output is read by a normalizing XmlReader. 當來回行程之後額外的正規化規則適用於屬性值\t\n\r在正規化時的屬性值中的空間就會被取代XmlReaderAdditional normalization rules apply for attribute values when round tripping since \t, \n and \r are replaced with a space in attribute values when normalized in an XmlReader.

  • Replace設定會告知XmlWriter取代新行字元與\r\n,這是 Microsoft Windows 作業系統所使用的新行格式。The Replace setting tells the XmlWriter to replace new line characters with \r\n, which is the new line format used by the Microsoft Windows operating system. 這有助於確保該檔案可以正確顯示的 [記事本] 或 Microsoft Word 應用程式。This helps to ensure that the file can be correctly displayed by the Notepad or Microsoft Word applications. 這項設定也會使用以保留字元的字元實體取代屬性中的新行。This setting also replaces new lines in attributes with character entities to preserve the characters. 這是預設值。This is the default value.

  • None設定會告知XmlWriter保持不變的輸入。The None setting tells the XmlWriter to leave the input unchanged. 不想讓任何新行處理時,會使用此設定。This setting is used when you do not want any new-line processing. 讀取的輸出時,這是很有用XmlReader,不會執行任何正規化 (例如XmlTextReader使用預設設定。)This is useful when the output is read by an XmlReader that does not do any normalization (for example, an XmlTextReader with default settings.)

下表顯示的輸出WriteString方法時所輸入的值取決於提供NewLineHandling屬性設定。The following tables show the output of the WriteString method when supplied with the input value depending on the NewLineHandling property setting. 寫入文字內容時,資料表會顯示輸出,以及寫入屬性值時。The tables show the output when writing text content and also when writing an attribute value.

Text Node Value:

\r\n\r\n \n\n \r\r \t\t
實體化Entitize & #D; \n&#D;\n \n\n &#D;&#D; \t\t
Replace \r\n\r\n \r\n\r\n \r\n\r\n \t\t
None \r\n\r\n \n\n \r\r \t\t

Attribute Value:

\r\n\r\n \n\n \r\r \t\t
實體化Entitize &#D;&#A;&#D;&#A; &#A;&#A; &#D;&#D; 		
Replace &#D;&#A;&#D;&#A; &#A;&#A; &#D;&#D; 		
None \r\n\r\n \n\n \r\r \t\t

注意

XmlWriter寫入 CDATA 區段中,註解或處理指示中的內容時,有下列行為。The XmlWriter has the following behavior when writing content within a CDATA section, comment, or processing instruction. 新行永遠不會取代其字元的實體,即使NewLineHandling屬性設定為EntitizeNew lines are never replaced with their character entities, even when the NewLineHandling property is set to Entitize. 這是因為在 CDATA 區段中,註解或處理指示中無法辨識的字元實體。This is because character entities are not recognized in CDATA sections, comments or processing instructions. 如果NewLineHandling屬性設定為NoneReplace,撰寫的文字節點的值時的行為是相同。If the NewLineHandling property is set to None or Replace, the behavior is the same as when writing a text node value.

下表說明哪些正規化XmlReader傳回每個輸入的泛空白字元。The following table describes what a normalizing XmlReader returns for each white space input. 如需詳細資訊,請參閱 2.11 和 W3C 的 3.3.3 XML 1.0 建議事項For more information, see sections 2.11 and 3.3.3 of the W3C XML 1.0 Recommendation.

注意

正規化的讀取器可以是任何XmlReader所建立的物件XmlReader.Create方法。A normalizing reader is any XmlReader object created by the XmlReader.Create method. 這些物件一律會執行 break 正規化和屬性的完整正規化。These objects always perform line break normalization and full normalization of attributes. XmlTextReader物件也可以是正規化的讀取器,它是否Normalization屬性設定為trueThe XmlTextReader object can also be a normalizing reader if it's Normalization property is set to true.

\r\n\r\n \n\n \r\r \t\t
文字節點值Text Node Value \n\n \n\n \n\n \t\t
屬性值Attribute Value 單一空格single space 單一空格single space 單一空格single space 單一空格single space

適用於