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 表示在新行和縮排上寫入個別項目,否則為 falsetrue to write individual elements on new lines and indent; otherwise, false. 預設為 falseThe 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.

適用於