System.Xml.XmlTextWriter.Indentation Property

Gets or sets how many IndentChars to write for each level in the hierarchy when XmlTextWriter.Formatting is set to Formatting.Indented.

Syntax

public int Indentation { get; set; }

Value

A int specifying the number of XmlTextWriter.IndentChar characters to use for each level. The default is 2.

Exceptions

TypeReason
ArgumentExceptionThe value to be set is less than zero.

Remarks

Note:

In the dnprdnext release, the recommended practice is to create System.Xml.XmlWriter instances using the erload:System.Xml.XmlWriter.Create method and the System.Xml.XmlWriterSettings class. This allows you to take full advantage of all the new features introduced in this release. For more information, see Creating XML Writers.

Indentation is performed on following node types: DocumentType, Element, Comment, ProcessingInstruction, and CDATASection. All other node types are not affected. The XmlTextWriter does not indent the internal DTD subset. However, you could do the following to apply formatting to the internal DTD subset.

Example

 String name = "Employees";
 String pubid = null;
 String sysid = null;
 String subset =
 @"
     <!ELEMENT Employees (Employee)+>
     <!ELEMENT Employee EMPTY>
     <!ATTLIST Employee firstname CDATA #REQUIRED>
     <!ENTITY Company 'Microsoft'>]>
 ";
 XmlTextWriter tw = new XmlTextWriter(Console.Out);
 tw.WriteDocType(name, pubid, sysid, subset);

Requirements

Namespace: System.Xml
Assembly: System.Xml (in System.Xml.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0