XmlTextWriter.WriteString(String) XmlTextWriter.WriteString(String) XmlTextWriter.WriteString(String) XmlTextWriter.WriteString(String) Method

Definizione

Scrive il contenuto di testo specificato.Writes the given text content.

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

Parametri

text
String String String String

Testo da scrivere.Text to write.

Eccezioni

La stringa di testo contiene una coppia di surrogati non valida.The text string contains an invalid surrogate pair.

Esempi

Nell'esempio seguente viene scritto un frammento XML.The following example writes an XML fragment.

#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   
   //Create a writer to write XML to the console.
   XmlTextWriter^ writer = nullptr;
   writer = gcnew 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();
}

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

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.

WriteStringesegue le operazioni seguentiWriteString does the following

  • I caratteri &, < &amp;e > vengono sostituiti rispettivamente con &lt;, e &gt;.The characters &, <, and > are replaced with &amp;, &lt;, and &gt;, respectively.

  • I valori di carattere nell'intervallo 0x-0x1F (esclusi i caratteri di spazio vuoto 0x9, 0xA e 0xD) vengono sostituiti da&#0; entità &#0x1Fdi caratteri numerici (fino a).Character values in the range 0x-0x1F (excluding white space characters 0x9, 0xA, and 0xD) are replaced with numeric character entities (&#0; through &#0x1F).

  • Se WriteString viene chiamato nel contesto di un valore di attributo, le virgolette doppie e singole vengono &quot; sostituite rispettivamente con e &apos; .If WriteString is called in the context of an attribute value, double and single quotes are replaced with &quot; and &apos; respectively.

Questa stringa test<item>test di input, ad esempio, viene scritta comeFor example, this input string test<item>test is written as

test&lt;item&gt;test  

Se text èoString.Empty,questo metodo scrive un nodo di testo senza contenuto dati. nullIf text is either null or String.Empty, this method writes a text node with no data content.

Si applica a