XmlWriterSettings.Indent XmlWriterSettings.Indent XmlWriterSettings.Indent XmlWriterSettings.Indent Property

정의

요소의 들여쓰기 여부를 나타내는 값을 가져오거나 설정합니다.Gets or sets a value indicating whether to indent elements.

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

속성 값

새 줄에 개별 요소를 들여 쓰면 true이고, 그렇지 않으면 false입니다.true to write individual elements on new lines and indent; otherwise, false. 기본값은 false입니다.The default is false.

예제

다음 예제에서는 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.

요소는 요소에 혼합된 콘텐츠가 없는으로 들여쓰기 됩니다.The elements are indented as long as the element does not contain mixed content. 한 번 합니다 WriteString 또는 WriteWhitespace 메서드를 호출 하는 혼합된 요소 내용 작성는 XmlWriter 들여쓰기를 중지 합니다.Once the WriteString or WriteWhitespace method is called to write out a mixed element content, the XmlWriter stops indenting. 혼합된 내용 요소 닫히면 들여쓰기를 다시 시작 합니다.The indenting resumes once the mixed content element is closed.

적용 대상