XmlTextWriter.XmlSpace XmlTextWriter.XmlSpace XmlTextWriter.XmlSpace XmlTextWriter.XmlSpace Property

Definizione

Ottiene un oggetto XmlSpace che rappresenta l'ambito xml:space corrente.Gets an XmlSpace representing the current xml:space scope.

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

Valore della proprietà

Oggetto XmlSpace che rappresenta l'ambito xml:space corrente.An XmlSpace representing the current xml:space scope.

ValueValue SignificatoMeaning
nessunoNone Valore predefinito qualora non esista alcun ambito xml:space.This is the default if no xml:space scope exists.
Impostazione predefinitaDefault L'ambito corrente è xml:space="default".The current scope is xml:space="default".
PreservePreserve L'ambito corrente è xml:space="preserve".The current scope is xml:space="preserve".

Esempi

Nell'esempio seguente viene usato WriteWhitespace il metodo per controllare la modalità di formattazione del file.The following example uses the WriteWhitespace method to control how the file is formatted.

#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

Commenti

Nota

A partire da .NET Framework 2,0, è consigliabile creare XmlWriter istanze usando il XmlWriter.Create metodo e la XmlWriterSettings classe per sfruttare le nuove funzionalità.Starting with the .NET Framework 2.0, we recommend that you create XmlWriter instances by using the XmlWriter.Create method and the XmlWriterSettings class to take advantage of new functionality.

Questa proprietà consente a un componente di individuare lo stato in cui un altro componente ha lasciato il writer.This property allows one component to find out in what state another component has left the writer.

Si applica a