XmlTextWriter.Indentation Eigenschap
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Hiermee haalt u op hoeveel IndentChars moet worden geschreven voor elk niveau in de hiërarchie wanneer Formatting deze is ingesteld op Formatting.Indented.
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
Waarde van eigenschap
Aantal voor IndentChars elk niveau. De standaard is 2.
Uitzonderingen
Deze eigenschap instellen op een negatieve waarde.
Voorbeelden
In het volgende voorbeeld wordt een XML-fragment geschreven.
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
Opmerkingen
Note
U wordt aangeraden om XmlWriter-exemplaren te maken met behulp van de XmlWriter.Create-methode en de XmlWriterSettings-klasse om te profiteren van nieuwe functionaliteit.
Inspringing wordt uitgevoerd op de volgende knooppunttypen: DocumentType, Element, Comment, ProcessingInstructionen CDATASection. Alle andere knooppunttypen worden niet beïnvloed. De XmlTextWriter interne DTD-subset wordt niet ingesprongen. U kunt echter het volgende doen om opmaak toe te passen op de interne DTD-subset.
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);