XmlWriterSettings.IndentChars XmlWriterSettings.IndentChars XmlWriterSettings.IndentChars XmlWriterSettings.IndentChars Property

定義

取得或設定縮排時使用的字元字串。Gets or sets the character string to use when indenting. Indent 屬性設為 true 時會使用這項設定。This setting is used when the Indent property is set to 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

屬性值

縮排時使用的字元字串。The character string to use when indenting. 它可以設為任何字串值。This can be set to any string value. 不過,若要確保有效的 XML,您應該只指定有效的空白字元 (例如,空格字元、定位字元、歸位字元或換行符號)。However, to ensure valid XML, you should specify only valid white space characters, such as space characters, tabs, carriage returns, or line feeds. 預設值為兩個空格。The default is two spaces.

例外狀況

範例

下列範例會建立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. XmlWriter擲回例外狀況,如果縮排字元會產生無效的 XML。The XmlWriter throws an exception if the indent characters would result in invalid XML.

適用於