XmlWriterSettings.Indent Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets or sets a value indicating whether to indent elements.

Namespace:  System.Xml
Assembly:  System.Xml (in System.Xml.dll)

Syntax

'Declaration
Public Property Indent As Boolean
public bool Indent { get; set; }

Property Value

Type: System.Boolean
true to write individual elements on new lines and indent; otherwise false. The default is false.

Remarks

This property only applies to XmlWriter instances that output text content; otherwise, this setting is ignored.

The elements are indented as long as the element does not contain mixed content. Once the WriteString or WriteWhitespace method is called to write out a mixed element content, the XmlWriter stops indenting. The indenting resumes once the mixed content element is closed.

For more information and code examples, see XML Data.

Examples

Dim output As New StringBuilder()

Dim settings As New XmlWriterSettings()
settings.Indent = True
settings.OmitXmlDeclaration = True
settings.NewLineOnAttributes = True

Using writer As XmlWriter = XmlWriter.Create(output, settings)
    writer.WriteStartElement("order")
    writer.WriteAttributeString("orderID", "367A54")
    writer.WriteAttributeString("date", "2001-05-03")
    writer.WriteElementString("price", "19.95")
    writer.WriteEndElement()

    writer.Flush()
End Using
OutputTextBlock.Text = output.ToString()

StringBuilder output = new StringBuilder();

    XmlWriterSettings settings = new XmlWriterSettings();
    settings.Indent = true;
    settings.OmitXmlDeclaration = true;
    settings.NewLineOnAttributes = true;

    using (XmlWriter writer = XmlWriter.Create(output, settings))
    {
    writer.WriteStartElement("order");
    writer.WriteAttributeString("orderID", "367A54");
    writer.WriteAttributeString("date", "2001-05-03");
    writer.WriteElementString("price", "19.95");
    writer.WriteEndElement();

    writer.Flush();
}

OutputTextBlock.Text = output.ToString();

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.