XmlWriterSettings.IndentChars Proprietà

Definizione

Ottiene o imposta la stringa di caratteri da usare per il rientro. Questa impostazione viene usata quando la proprietà Indent è impostata su 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

Valore della proprietà

String

Stringa di caratteri da usare per il rientro. Può essere impostata su qualsiasi valore stringa. Tuttavia, per essere sicuri che l'XML sia valido, specificare solo spazi vuoti validi, ad esempio spazi, tabulazioni, ritorni a capo o avanzamenti riga. Il valore predefinito è due spazi.

Eccezioni

Il valore assegnato all'elemento IndentChars è null.

Esempio

Nell'esempio seguente viene creato un XmlWriter oggetto che utilizza il carattere TAB per il rientro.

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

Commenti

Questa proprietà si applica solo alle XmlWriter istanze che generano contenuto di testo. In caso contrario, questa impostazione viene ignorata. Genera XmlWriter un'eccezione se i caratteri di rientro generano codice XML non valido.

Si applica a