Specifies a set of features to support on the System.Xml.XmlWriter object created by the erload:System.Xml.XmlWriter.Create method.
See Also: XmlWriterSettings Members
The erload:System.Xml.XmlWriter.Create method is the preferred mechanism for obtaining System.Xml.XmlWriter instances. The erload:System.Xml.XmlWriter.Create method uses the System.Xml.XmlWriterSettings class to specify which features to implement in the System.Xml.XmlWriter object that is created.
If you're using the System.Xml.XmlWriter object with the System.Xml.Xsl.XslCompiledTransform.Transform(string, XmlWriter) method, you should use the System.Xml.Xsl.XslCompiledTransform.OutputSettings property to obtain an System.Xml.XmlWriterSettings object with the correct settings. This ensures that the created System.Xml.XmlWriter object has the correct output settings.
The System.Xml.XmlWriterSettings class provides properties that control data conformance and output format.
For data conformance checks and auto-corrections, use these properties:
XmlWriterSettings.CheckCharacters |
Whether to check that characters are in the legal XML character set, as defined by W3C. |
true or false |
true |
XmlWriterSettings.ConformanceLevel |
Whether to check that output is a well-formed XML 1.0 document or fragment. |
ConformanceLevel.Document (document-level), ConformanceLevel.Fragment (fragment-level), or ConformanceLevel.Auto (auto-detection) |
ConformanceLevel.Document (document-level conformance) |
XmlWriterSettings.WriteEndDocumentOnClose |
Whether to add closing tags to all unclosed elements when the XmlWriter.Close method is called. |
true or false |
true |
To specify output format, use these properties:
XmlWriterSettings.Encoding |
Text encoding to use. |
System.Text.Encoding value | |
XmlWriterSettings.Indent |
Whether to indent elements |
true or false |
false (no indentation) |
XmlWriterSettings.IndentChars |
Character string to use when indenting (used when XmlWriterSettings.Indent is set to true). |
String |
Two spaces |
XmlWriterSettings.NewLineChars |
Character string to use for line breaks. |
String |
\r\n (carriage return, line feed) |
XmlWriterSettings.NewLineHandling |
How to handle newline characters. |
System.Xml.NewLineHandling value: NewLineHandling.Entitize (normalize), NewLineHandling.Replace (replace), or NewLineHandling.None (leave unchanged) |
NewLineHandling.Replace (replace with characters specified by XmlWriterSettings.NewLineChars) |
XmlWriterSettings.NewLineOnAttributes |
Whether to write attributes on individual lines (has no effect when XmlWriterSettings.Indent is false). |
true or false |
false |
XmlWriterSettings.OmitXmlDeclaration |
Whether to write an XML declaration. |
true or false |
false |