XmlWriterSettings.IndentChars Property


Gets or sets the character string to use when indenting. This setting is used when the Indent property is set to true.

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

public string IndentChars { get; set; }

Property Value

Type: System.String

The character string to use when indenting. This can be set to any string value. However, to ensure valid XML, you should specify only valid white space characters, such as space characters, tabs, carriage returns, or line feeds. The default is two spaces.

Exception Condition

The value assigned to the IndentChars is null.

This property only applies to XmlWriter instances that output text content; otherwise, this setting is ignored. The XmlWriter throws an exception if the indent characters would result in invalid XML.

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

using System;
using System.IO;
using System.Xml;
using System.Text;

public class Sample {

  public static void Main() {

    XmlWriter writer = null;

    try {

       // Create an XmlWriterSettings object with the correct options. 
       XmlWriterSettings settings = new XmlWriterSettings();
       settings.Indent = true;
       settings.IndentChars = ("\t");
       settings.OmitXmlDeclaration = true;

       // Create the XmlWriter object and write some content.
       writer = XmlWriter.Create("data.xml", settings);
       writer.WriteElementString("item", "tesing");


     finally  {
        if (writer != null)

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