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 */
public NewLineHandling get_NewLineHandling ()

/** @property */
public void set_NewLineHandling (NewLineHandling value)

public function get NewLineHandling () : NewLineHandling

public function set NewLineHandling (value : NewLineHandling)

Not applicable.

Property Value

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 System.Xml.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

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

.NET Compact Framework

Supported in: 2.0

XNA Framework

Supported in: 1.0

Community Additions

ADD
Show:
© 2014 Microsoft