XmlTextWriter.XmlSpace Propriété

Définition

Obtient un XmlSpace représentant la portée xml:space en cours.

public:
 virtual property System::Xml::XmlSpace XmlSpace { System::Xml::XmlSpace get(); };
public override System.Xml.XmlSpace XmlSpace { get; }
member this.XmlSpace : System.Xml.XmlSpace
Public Overrides ReadOnly Property XmlSpace As XmlSpace

Valeur de propriété

Obtient un XmlSpace représentant la portée xml:space en cours.

Valeur Signification
Aucun Valeur par défaut si aucune portée xml:space n'existe.
Par défaut La portée actuelle est xml:space= "default".
Preserve La portée actuelle est xml:space= "preserve".

Exemples

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

#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   
   // Create the writer.
   XmlTextWriter^ writer = nullptr;
   writer = gcnew XmlTextWriter( "ws.html", nullptr );
   
   // Write an element (this one is the root).
   writer->WriteStartElement( "p" );
   
   // Write the xml:space attribute.
   writer->WriteAttributeString( "xml", "space", nullptr, "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();
}
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

Notes

À compter de .NET Framework 2.0, nous vous recommandons de créer XmlWriter des instances à l’aide de la XmlWriter.Create méthode et de la XmlWriterSettings classe pour tirer parti des nouvelles fonctionnalités.

Cette propriété permet à un composant de déterminer dans quel état un autre composant a quitté l’enregistreur.

S’applique à