XmlWriterSettings.Indent プロパティ

定義

要素にインデントを設定するかどうかを示す値を取得または設定します。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、それ以外の場合は falsetrue 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.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コンテンツを出力するインスタンスにのみ適用されます。それ以外の場合、この設定は無視されます。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.

適用対象