XmlWriterSettings.Indent Property

 

Gets or sets a value indicating whether to indent elements.

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

Public Property Indent As Boolean

Property Value

Type: System.Boolean

true to write individual elements on new lines and indent; otherwise, false. The default is false.

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.

The following example creates an XmlWriter object that uses the TAB character for indentation.

Imports System
Imports System.IO
Imports System.Xml
Imports System.Text
Imports Microsoft.VisualBasic

Public Class Sample 

  Public Shared Sub Main() 

    Dim writer As XmlWriter = Nothing

    Try 

       ' Create an XmlWriterSettings object with the correct options. 
       Dim settings As XmlWriterSettings = New XmlWriterSettings()
       settings.Indent = true
       settings.IndentChars = (ControlChars.Tab)
       settings.OmitXmlDeclaration = true

       ' Create the XmlWriter object and write some content.
       writer = XmlWriter.Create("data.xml", settings)
       writer.WriteStartElement("book")
       writer.WriteElementString("item", "tesing")
       writer.WriteEndElement()

       writer.Flush()

      Finally
         If Not (writer Is Nothing) Then
            writer.Close()
         End If
      End Try

   End Sub 
End Class 

Universal Windows Platform
Available since 8
.NET Framework
Available since 2.0
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
Show: