संपादित करें

इसके माध्यम से साझा किया गया


XmlWriterSettings.NewLineHandling Property

Definition

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

Property Value

One of the 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 the character(s) specificed in the NewLineChars property. This setting also replaces new lines in attributes with character entities to preserve the characters. It is also 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 (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

Note

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.

Note

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

Applies to