XmlFormattingOptions Class
Controls whitespace and layout decisions used by Formatter.
public sealed class XmlFormattingOptionsExample
var tree = XmlSyntaxTree.ParseText("<root><item id=\"1\"/></root>");
var options = new XmlFormattingOptions { IndentationSize = 4, NewLine = "\r\n", SpaceAroundEquals = true };
var formatted = Formatter.Format(tree.GetRoot(), options);
Assert.Equal("<root>\r\n <item id = \"1\" />\r\n</root>", formatted.ToFullString());Constructors
| Name | Description |
|---|---|
| XmlFormattingOptions() |
XmlFormattingOptions()
XmlFormattingOptions.cspublic XmlFormattingOptions()No documentation is available.
Properties
| Name | Description |
|---|---|
| AttributeWrapping | Gets a value indicating whether each attribute of an element that has more than one goes on its own line, indented one level deeper than the element. |
| Default | |
| IndentationSize | Gets the number of spaces per indentation level. It is ignored when XmlFormattingOptions.UseTabs is true. The default is 2. |
| NewLine | Gets the line break written between the nodes the formatter puts on their own line. The default is "\n". |
| PreserveSingleLineElements | Gets a value indicating whether an element written on a single line is kept as it is, instead of putting each of its children on its own line. |
| SpaceAroundEquals | Gets a value indicating whether the equals sign of each attribute is written with a space on both sides, as in name = "value". |
| SpaceBeforeSelfClosingSlash | Gets a value indicating whether a self-closing tag ends with /> instead of />. The default is true. |
| UseTabs | Gets a value indicating whether each indentation level is a tab instead of XmlFormattingOptions.IndentationSize spaces. |
AttributeWrapping
XmlFormattingOptions.csGets a value indicating whether each attribute of an element that has more than one goes on its own line, indented one level deeper than the element.
public bool AttributeWrapping { get; init; }Property value
Remarks
It applies to the elements the formatter puts on their own line, not to those inside text.
Default
XmlFormattingOptions.csIndentationSize
XmlFormattingOptions.csGets the number of spaces per indentation level. It is ignored when XmlFormattingOptions.UseTabs is true. The default is 2.
public int IndentationSize { get; init; }Property value
NewLine
XmlFormattingOptions.csPreserveSingleLineElements
XmlFormattingOptions.csGets a value indicating whether an element written on a single line is kept as it is, instead of putting each of its children on its own line.
public bool PreserveSingleLineElements { get; init; }Property value
Remarks
The element still starts on its own line. Its whitespace is kept, and its attributes stay on its first line even when XmlFormattingOptions.AttributeWrapping is set.
SpaceAroundEquals
XmlFormattingOptions.csSpaceBeforeSelfClosingSlash
XmlFormattingOptions.csUseTabs
XmlFormattingOptions.csGets a value indicating whether each indentation level is a tab instead of XmlFormattingOptions.IndentationSize spaces.
public bool UseTabs { get; init; }