XmlWriterSettings.IndentChars 속성

정의

들여쓰기에 사용할 문자열을 가져오거나 설정합니다. 이 설정은 Indent 속성이 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

속성 값

들여쓰기에 사용할 문자열입니다. 이 속성에 설정할 수 있는 문자열 값에는 제한이 없습니다. 그러나 XML을 올바르게 유지하려면 공백 문자, 탭, 캐리지 리턴 또는 줄 바꿈 같은 유효한 공백 문자만 지정해야 합니다. 기본값은 공백 두 개입니다.

예외

IndentChars에 할당된 값이 null인 경우

예제

다음 예제에서는 들여쓰기를 위해 TAB 문자를 사용하는 개체를 만듭니다 XmlWriter .

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.IO
Imports System.Xml
Imports System.Text

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 만 적용되며, 그렇지 않으면 이 설정이 무시됩니다. 들 XmlWriter 여쓰기 문자가 잘못된 XML을 발생시킬 경우 는 예외를 throw합니다.

적용 대상