XmlFormattingOptions Class

Controls whitespace and layout decisions used by Formatter.

public sealed class XmlFormattingOptions

Example

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

NameDescription
XmlFormattingOptions()

XmlFormattingOptions()

XmlFormattingOptions.cs
public XmlFormattingOptions()

No documentation is available.

Properties

NameDescription
AttributeWrappingGets 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
IndentationSizeGets the number of spaces per indentation level. It is ignored when XmlFormattingOptions.UseTabs is true. The default is 2.
NewLineGets the line break written between the nodes the formatter puts on their own line. The default is "\n".
PreserveSingleLineElementsGets 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.
SpaceAroundEqualsGets a value indicating whether the equals sign of each attribute is written with a space on both sides, as in name = "value".
SpaceBeforeSelfClosingSlashGets a value indicating whether a self-closing tag ends with /> instead of />. The default is true.
UseTabsGets a value indicating whether each indentation level is a tab instead of XmlFormattingOptions.IndentationSize spaces.

AttributeWrapping

XmlFormattingOptions.cs

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.

public bool AttributeWrapping { get; init; }

Property value

bool

Remarks

It applies to the elements the formatter puts on their own line, not to those inside text.

public static XmlFormattingOptions Default { get; }

Property value

XmlFormattingOptions

No documentation is available.

Gets 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

int

Gets the line break written between the nodes the formatter puts on their own line. The default is "\n".

public string NewLine { get; init; }

Property value

string

PreserveSingleLineElements

XmlFormattingOptions.cs

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.

public bool PreserveSingleLineElements { get; init; }

Property value

bool

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.cs

Gets a value indicating whether the equals sign of each attribute is written with a space on both sides, as in name = "value".

public bool SpaceAroundEquals { get; init; }

Property value

bool

SpaceBeforeSelfClosingSlash

XmlFormattingOptions.cs

Gets a value indicating whether a self-closing tag ends with /> instead of />. The default is true.

public bool SpaceBeforeSelfClosingSlash { get; init; }

Property value

bool

Gets a value indicating whether each indentation level is a tab instead of XmlFormattingOptions.IndentationSize spaces.

public bool UseTabs { get; init; }

Property value

bool