XmlWriterSettings.IndentChars 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
인덴팅할 때 사용할 문자 문자열을 가져오거나 설정합니다. 이 설정은 속성이 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됩니다.