XmlWriterSettings.Indent Propriedade
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Obtém ou define um valor que indica se deve indentar elementos.
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
Valor de Propriedade
true escrever elementos individuais em novas linhas e indentações; caso contrário, false. A predefinição é false.
Exemplos
O exemplo seguinte cria um XmlWriter objeto que utiliza o carácter TAB para indentação.
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
Observações
Esta propriedade aplica-se apenas a XmlWriter instâncias que produzem conteúdo de texto; caso contrário, esta definição é ignorada.
Os elementos são indentados desde que o elemento não contenha conteúdo misto. Uma vez chamado o WriteString método ou WriteWhitespace para escrever um conteúdo de elemento misto, o XmlWriter método deixa de indentar. O recuo recomeça assim que o elemento de conteúdo misto é fechado.