XmlWriterSettings.IndentChars Propriété
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Obtient ou définit la chaîne de caractères à utiliser lors de la mise en retrait. Ce paramètre est utilisé lorsque la Indent propriété est définie sur 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
Valeur de propriété
Chaîne de caractères à utiliser lors de la mise en retrait. Cette valeur peut être définie sur n’importe quelle valeur de chaîne. Toutefois, pour garantir le code XML valide, vous devez spécifier uniquement des espaces blancs valides, tels que des espaces, des onglets, des retours chariot ou des flux de lignes. La valeur par défaut est deux espaces.
Exceptions
La valeur affectée à l’objet IndentChars est null.
Exemples
L’exemple suivant crée un XmlWriter objet qui utilise le caractère TAB pour la mise en retrait.
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
Remarques
Cette propriété s’applique uniquement aux XmlWriter instances qui génèrent du contenu de texte ; sinon, ce paramètre est ignoré. L’exception XmlWriter lève une exception si les caractères de retrait entraînent un code XML non valide.