Freigeben über


XmlTextWriter.Indentation-Eigenschaft

Ruft ab oder legt fest, wie viele IndentChars für jede Ebene der Hierarchie geschrieben werden sollen, wenn Formatting auf Formatting.Indented festgelegt ist.

Namespace: System.Xml
Assembly: System.Xml (in system.xml.dll)

Syntax

'Declaration
Public Property Indentation As Integer
'Usage
Dim instance As XmlTextWriter
Dim value As Integer

value = instance.Indentation

instance.Indentation = value
public int Indentation { get; set; }
public:
property int Indentation {
    int get ();
    void set (int value);
}
/** @property */
public int get_Indentation ()

/** @property */
public void set_Indentation (int value)
public function get Indentation () : int

public function set Indentation (value : int)

Eigenschaftenwert

Anzahl von IndentChars für jede Ebene. Der Standardwert ist 2.

Ausnahmen

Ausnahmetyp Bedingung

ArgumentException

Diese Eigenschaft wird auf einen negativen Wert festgelegt.

Hinweise

Hinweis

Die empfohlene Vorgehensweise für die Version Microsoft .NET Framework, Version 2.0 besteht darin, mithilfe der System.Xml.XmlWriter.Create-Methode und der XmlWriterSettings-Klasse XmlWriter-Instanzen zu erstellen. So können Sie alle neuen Features dieser Version in vollem Umfang nutzen. Weitere Informationen finden Sie unter Erstellen von XML-Writern.

Einzüge werden für die folgenden Knotentypen ausgeführt: DocumentType, Element, Comment, ProcessingInstruction und CDATASection. Alle anderen Knotentypen sind nicht betroffen. Der XmlTextWriter zieht die Teilmenge der internen DTD nicht ein. Sie können jedoch wie folgt vorgehen, um der Teilmenge der internen DTD eine Formatierung zuzuweisen.

 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);

Beispiel

Im folgenden Beispiel wird ein XML-Fragment geschrieben.

Option Explicit
Option Strict

Imports System
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 'Main 
End Class 'Sample
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();  

  }

}
#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   
   //Create a writer to write XML to the console.
   XmlTextWriter^ writer = nullptr;
   writer = gcnew 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();
}
import System.*;
import System.IO.*;
import System.Xml.*;

public class Sample
{
    public static void main(String[] args)
    {
        //Create a writer to write XML to the console.
        XmlTextWriter writer = null;
        writer = new XmlTextWriter(Console.get_Out());

        //Use indentation for readability.
        writer.set_Formatting(Formatting.Indented);
        writer.set_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();
    } //main 
} //Sample

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

.NET Compact Framework

Unterstützt in: 2.0, 1.0

Siehe auch

Referenz

XmlTextWriter-Klasse
XmlTextWriter-Member
System.Xml-Namespace
IndentChar
Formatting-Enumeration