XmlWriterSettings.Indent 속성

정의

요소의 들여쓰기 여부를 나타내는 값을 가져오거나 설정합니다.

public:
 property bool Indent { bool get(); void set(bool value); };
public bool Indent { get; set; }
member this.Indent : bool with get, set
Public Property Indent As Boolean

속성 값

Boolean

새 줄에 개별 요소를 들여 쓰면 true이고, 그렇지 않으면 false입니다. 기본값은 false입니다.

예제

다음 예제에서는 들여쓰기를 위해 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 만 적용되며, 그렇지 않으면 이 설정이 무시됩니다.

요소에 혼합 콘텐츠가 포함되지 않는 한 요소가 들여쓰기됩니다. WriteString 혼합 요소 콘텐츠를 쓰기 위해 또는 WriteWhitespace 메서드가 호출되면 들여쓰기를 XmlWriter 중지합니다. 혼합 콘텐츠 요소가 닫힌 후에는 인덴팅이 다시 시작됩니다.

적용 대상