Partager via


XmlTextWriter.WriteWhitespace(String) Méthode

Définition

Écrit l’espace blanc donné.

public:
 override void WriteWhitespace(System::String ^ ws);
public override void WriteWhitespace(string? ws);
public override void WriteWhitespace(string ws);
override this.WriteWhitespace : string -> unit
Public Overrides Sub WriteWhitespace (ws As String)

Paramètres

ws
String

Chaîne de caractères d’espace blanc.

Exceptions

La chaîne contient des caractères d’espace non blancs.

Exemples

L’exemple suivant utilise la WriteWhitespace méthode pour contrôler la mise en forme du fichier.

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

public class Sample
{
  public static void Main()
  {
    // Create the writer.
    XmlTextWriter writer = null;
    writer = new XmlTextWriter ("ws.html", null);

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

    // Write the xml:space attribute.
    writer.WriteAttributeString("xml", "space", null, "preserve");

    // Verify that xml:space is set properly.
    if (writer.XmlSpace == XmlSpace.Preserve)
      Console.WriteLine("xmlspace is correct!");

    // Write out the HTML elements.  Insert white space
    // between 'something' and 'Big'
    writer.WriteString("something");
    writer.WriteWhitespace("  ");
    writer.WriteElementString("b", "B");
    writer.WriteString("ig");

    // Write the root end element.
    writer.WriteEndElement();

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

Imports System.IO
Imports System.Xml

Public Class Sample
    
    Public Shared Sub Main()
        ' Create the writer.
        Dim writer As XmlTextWriter = Nothing
        writer = New XmlTextWriter("ws.html", Nothing)
        
        ' Write an element (this one is the root).
        writer.WriteStartElement("p")
        
        ' Write the xml:space attribute.
        writer.WriteAttributeString("xml", "space", Nothing, "preserve")
        
        ' Verify that xml:space is set properly.
        If writer.XmlSpace = XmlSpace.Preserve Then
            Console.WriteLine("xmlspace is correct!")
        End If 
        ' Write out the HTML elements.  Insert white space
        ' between 'something' and 'Big'.
        writer.WriteString("something")
        writer.WriteWhitespace("  ")
        writer.WriteElementString("b", "B")
        writer.WriteString("ig")
        
        ' Write the root end element.
        writer.WriteEndElement()
        
        ' Write the XML to file and close the writer.
        writer.Close()
    End Sub
End Class

Remarques

Note

Nous vous recommandons de créer XmlWriter instances en utilisant la méthode XmlWriter.Create et la classe XmlWriterSettings pour tirer parti de nouvelles fonctionnalités.

Cette méthode est utilisée pour mettre en forme manuellement votre document. Utilisez la propriété pour que l’enregistreur Formatting formate automatiquement la sortie.

S’applique à

Voir aussi