XmlWriterSettings.IndentChars Właściwość

Definicja

Pobiera lub ustawia ciąg znaków do użycia podczas wcięcia. To ustawienie jest używane, gdy właściwość jest ustawiona Indent na truewartość .

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

Wartość właściwości

Ciąg znaków, który ma być używany podczas wcięcia. Można to ustawić na dowolną wartość ciągu. Jednak aby zapewnić prawidłowy kod XML, należy określić tylko prawidłowe znaki odstępu, takie jak znaki spacji, tabulatory, znaki powrotu karetki lub kanały informacyjne wiersza. Wartość domyślna to dwie spacje.

Wyjątki

Wartość przypisana do elementu IndentChars to null.

Przykłady

Poniższy przykład tworzy XmlWriter obiekt, który używa znaku TAB do wcięcia.

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

Uwagi

Ta właściwość ma zastosowanie tylko do XmlWriter wystąpień wyjściowych zawartości tekstowej. W przeciwnym razie to ustawienie jest ignorowane. Obiekt XmlWriter zgłasza wyjątek, jeśli znaki wcięcia spowodują nieprawidłowy kod XML.

Dotyczy