XmlWriterSettings.Indent Propiedad

Definición

Obtiene o establece un valor que indica si se va a aplicar sangría a los 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 propiedad

Boolean

Es true para escribir elementos individuales en líneas nuevas y aplicar sangría; en caso contrario, es false. De manera predeterminada, es false.

Ejemplos

En el ejemplo siguiente se crea un XmlWriter objeto que usa el carácter TAB para la sangría.

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

Comentarios

Esta propiedad solo se aplica a XmlWriter instancias que generan contenido de texto; de lo contrario, se omite esta configuración.

Los elementos tienen sangría siempre que el elemento no contenga contenido mixto. WriteString Una vez que se llama al método o WriteWhitespace para escribir un contenido de elemento mixto, detiene la XmlWriter sangría. La sangría se reanuda una vez que se cierra el elemento de contenido mixto.

Se aplica a