Export (0) Print
Expand All

XmlWriterSettings.NewLineHandling Property

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

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

public NewLineHandling NewLineHandling { get; set; }

Property Value

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

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 not want any new-line processing. This is useful when the output is read by an XmlReader that does not do any normalization (for example, an XmlTextReader with default settings.)

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. The XmlTextReader object can also be a normalizing reader if it's Normalization property is set to true.

\r\n

\n

\r

\t

Text Node Value

\n

\n

\n

\t

Attribute Value

single space

single space

single space

single space

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft