System.Xml.XmlWriterSettings.NewLineHandling Property

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

Syntax

public NewLineHandling NewLineHandling { get; set; }

Value

Documentation for this section has not yet been entered.

Remarks

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

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

  • The NewLineHandling.Replace setting tells the System.Xml.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 NewLineHandling.None setting tells the System.Xml.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 System.Xml.XmlReader that does not do any normalization (for example, an System.Xml.XmlTextReader with default settings.)

The following tables show the output of the XmlWriter.WriteString(string) method when supplied with the input value depending on the XmlWriterSettings.NewLineHandling property setting. The tables show the output when writing text content and also when writing an attribute value.

Text Node Value:

Entitize

&#D;\n

\n

&#D;

\t

Replace

\r\n

\r\n

\r\n

\t

None

\r\n

\n

\r

\t

Attribute Value:

Entitize

&#D;&#A;

&#A;

&#D;

	

Replace

&#D;&#A;

&#A;

&#D;

	

None

\r\n

\n

\r

\t

Note:

The System.Xml.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 XmlWriterSettings.NewLineHandling property is set to NewLineHandling.Entitize. This is because character entities are not recognized in CDATA sections, comments or processing instructions. If the XmlWriterSettings.NewLineHandling property is set to NewLineHandling.None or NewLineHandling.Replace, the behavior is the same as when writing a text node value.

The following table describes what a normalizing System.Xml.XmlReader returns for each white space input. For more information, see sections 2.11 and 3.3.3 of the W3C tp://www.w3.org/TR/REC-xml/.

Note:

A normalizing reader is any System.Xml.XmlReader object created by the erload:System.Xml.XmlReader.Create method. These objects always perform line break normalization and full normalization of attributes. The System.Xml.XmlTextReader object can also be a normalizing reader if it's XmlTextReader.Normalization property is set to true.

Text Node Value

\n

\n

\n

\t

Attribute Value

single space

single space

single space

single space

Requirements

Namespace: System.Xml
Assembly: System.Xml (in System.Xml.dll)
Assembly Versions: 2.0.0.0, 4.0.0.0
Since: .NET 2.0