XmlTextWriter.WriteWhitespace(String) Metodo
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Scrive lo spazio vuoto specificato.
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)
Parametri
- ws
- String
Stringa di caratteri spazio vuoto.
Eccezioni
La stringa contiene caratteri di non spazio.
Esempio
Nell'esempio seguente viene utilizzato il WriteWhitespace
metodo per controllare la formattazione del file.
#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à.
Questo metodo viene usato per formattare manualmente il documento. Utilizzare la Formatting proprietà per fare in modo che il writer formatti automaticamente l'output.
Si applica a
Vedi anche
Commenti e suggerimenti
https://aka.ms/ContentUserFeedback.
Presto disponibile: Nel corso del 2024 verranno gradualmente disattivati i problemi di GitHub come meccanismo di feedback per il contenuto e ciò verrà sostituito con un nuovo sistema di feedback. Per altre informazioni, vedereInvia e visualizza il feedback per