XmlWriterSettings.Indent 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定一個值,指示是否縮排元素。
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在新行上書寫個別元素並縮排;否則,。 false 預設值為 false。
範例
以下範例建立一個 XmlWriter 物件,使用 TAB 字元進行縮排。
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 輸出文字內容的實例;否則此設定將被忽略。
只要元素不包含混合內容,這些元素就會縮排。 一旦 WriteString 呼叫 or WriteWhitespace 方法來寫出混合元素內容,該 XmlWriter 方法就會停止縮排。 當混合內容元素關閉後,縮排會恢復。