XmlWriterSettings.IndentChars XmlWriterSettings.IndentChars XmlWriterSettings.IndentChars XmlWriterSettings.IndentChars Property

定義

インデント処理を行うときに使用する文字列を取得または設定します。Gets or sets the character string to use when indenting. この設定は、Indent プロパティが true に設定されている場合に使用します。This setting is used when the Indent property is set to true.

public:
 property System::String ^ IndentChars { System::String ^ get(); void set(System::String ^ value); };
public string IndentChars { get; set; }
member this.IndentChars : string with get, set
Public Property IndentChars As String

プロパティ値

インデント処理を行うときに使用する文字列。The character string to use when indenting. これには任意の文字列値を設定できます。This can be set to any string value. ただし、有効な XML にするには、空白、タブ、復帰、ライン フィードなどの有効な空白文字だけを指定する必要があります。However, to ensure valid XML, you should specify only valid white space characters, such as space characters, tabs, carriage returns, or line feeds. 既定値は 2 つのスペースです。The default is two spaces.

例外

IndentChars に代入された値が null です。The value assigned to the IndentChars is null.

次の例では、作成、XmlWriterインデントにタブ文字を使用するオブジェクト。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.WriteStartElement("book");
       writer.WriteElementString("item", "tesing");
       writer.WriteEndElement();
	
       writer.Flush();

     } 
     finally  {
        if (writer != null)
          writer.Close();
     }
  } 
} 
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 

注釈

このプロパティはXmlWriterインスタンスのテキストの内容を出力する。 それ以外の場合、この設定は無視されます。This property only applies to XmlWriter instances that output text content; otherwise, this setting is ignored. XmlWriterインデント文字が無効な XML になる場合に例外をスローします。The XmlWriter throws an exception if the indent characters would result in invalid XML.

適用対象