XmlWriterSettings.NewLineHandling Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets or sets a value indicating whether to normalize line breaks in the output.

Namespace:  System.Xml
Assembly:  System.Xml (in System.Xml.dll)

Syntax

'Declaration
Public Property NewLineHandling As NewLineHandling
public NewLineHandling NewLineHandling { get; set; }

Property Value

Type: System.Xml.NewLineHandling
One of the System.Xml.NewLineHandling values. The default is Replace.

Remarks

This setting applies when writing text content or attribute values. Each of the NewLineHandling values is described below:

  • The Entitize setting tells the XmlWriter to replace new line characters that would not be otherwise preserved by a normalizing XmlReader with character entities. This is useful in round-trip scenarios where the output is read by a normalizing XmlReader. Additional 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.

  • 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. 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.

  • The None setting tells the XmlWriter to leave the input unchanged. This setting is used when you do not want any new-line processing. This is useful when the output is read by an XmlReader that does not do any normalization.

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

\n

\r

\t

Entitize

&#D;\n

\n

&#D;

\t

Replace

\r\n

\r\n

\r\n

\t

None

\r\n

\n

\r

\t

Attribute Value:

\r\n

\n

\r

\t

Entitize

&#D;&#A;

&#A;

&#D;

	

Replace

&#D;&#A;

&#A;

&#D;

	

None

\r\n

\n

\r

\t

NoteNote:

The XmlWriter has the following behavior when writing content within a CDATA section, comment, or processing instruction. New lines are never replaced with their character entities, even when the NewLineHandling property is set to Entitize. This is because character entities are not recognized in CDATA sections, comments or processing instructions. If the NewLineHandling property is set to None or Replace, the behavior is the same as when writing a text node value.

The following table describes what a normalizing XmlReader returns for each white space input. For more information, see sections 2.11 and 3.3.3 of the W3C XML 1.0 Recommendation.

NoteNote:

A normalizing reader is any XmlReader object created by the XmlReader.Create method. These objects always perform line break normalization and full normalization of attributes.

\r\n

\n

\r

\t

Text Node Value

\n

\n

\n

\t

Attribute Value

single space

single space

single space

single space

For more information and code examples, see XML Data.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.