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 を確保するには、空白文字、タブ、復帰、改行などの有効な空白文字のみを指定する必要があります。 既定値は 2 つのスペースです。
例外
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 インスタンスにのみ適用されます。それ以外の場合、この設定は無視されます。 インデント文字が無効な XML になる場合、 XmlWriter は例外をスローします。