XmlTextWriter.Indentation Özellik

Tanım

olarak ayarlandığında Formattinghiyerarşideki Formatting.Indented her düzey için kaç IndentChar yazacaklarını alır veya ayarlar.

public:
 property int Indentation { int get(); void set(int value); };
public int Indentation { get; set; }
member this.Indentation : int with get, set
Public Property Indentation As Integer

Özellik Değeri

Her düzey için sayısı IndentChars . Varsayılan 2'dir.

Özel durumlar

Bu özellik negatif bir değere ayarlanıyor.

Örnekler

Aşağıdaki örnek bir XML parçası yazar.

using System;
using System.IO;
using System.Xml;

public class Sample
{

  public static void Main()
  {
     //Create a writer to write XML to the console.
     XmlTextWriter writer = null;
     writer = new XmlTextWriter (Console.Out);

     //Use indentation for readability.
     writer.Formatting = Formatting.Indented;
     writer.Indentation = 4;

     //Write an element (this one is the root).
     writer.WriteStartElement("book");

     //Write the title element.
     writer.WriteStartElement("title");
     writer.WriteString("Pride And Prejudice");
     writer.WriteEndElement();

     //Write the close tag for the root element.
     writer.WriteEndElement();

     //Write the XML to file and close the writer.
     writer.Close();
  }
}
Option Explicit
Option Strict

Imports System.IO
Imports System.Xml

Public Class Sample
    
    Public Shared Sub Main()
        'Create a writer to write XML to the console.
        Dim writer As XmlTextWriter = Nothing
        writer = New XmlTextWriter(Console.Out)
        
        'Use indentation for readability.
        writer.Formatting = Formatting.Indented
        writer.Indentation = 4
        
        'Write an element (this one is the root).
        writer.WriteStartElement("book")
        
        'Write the title element.
        writer.WriteStartElement("title")
        writer.WriteString("Pride And Prejudice")
        writer.WriteEndElement()
        
        'Write the close tag for the root element.
        writer.WriteEndElement()
        
        'Write the XML to file and close the writer.
        writer.Close()
    End Sub
End Class

Açıklamalar

Note

XmlWriter öneririz ki, yeni işlevlerden yararlanmak için XmlWriter.Create yöntemi ve XmlWriterSettings sınıfını kullanarak örnekler oluşturun.

Girintileme şu düğüm türlerinde gerçekleştirilir: DocumentType, Element, Comment, ProcessingInstructionve CDATASection. Diğer tüm düğüm türleri etkilenmez. , XmlTextWriter iç DTD alt kümesini girintili yapmaz. Ancak, iç DTD alt kümesine biçimlendirme uygulamak için aşağıdakileri yapabilirsiniz.

String name = "Employees";
String pubid = null;
String sysid = null;
String subset =
@"
    <!ELEMENT Employees (Employee)+>
    <!ELEMENT Employee EMPTY>
    <!ATTLIST Employee firstname CDATA #REQUIRED>
    <!ENTITY Company 'Microsoft'>]>
";
XmlTextWriter tw = new XmlTextWriter(Console.Out);
tw.WriteDocType(name, pubid, sysid, subset);

Şunlara uygulanır

Ayrıca bkz.