XmlTextWriter.WriteCharEntity(Char) Metodo

Definizione

Forza la generazione di un'entità carattere per il valore del carattere Unicode specificato.

public:
 override void WriteCharEntity(char ch);
public override void WriteCharEntity (char ch);
override this.WriteCharEntity : char -> unit
Public Overrides Sub WriteCharEntity (ch As Char)

Parametri

ch
Char

Carattere Unicode per il quale generare l'entità di caratteri.

Eccezioni

Il carattere è contenuto nell'intervallo di caratteri della coppia di surrogati, 0xd800 - 0xdfff; o il testo genera un documento XML di formato non corretto.

L'elemento WriteState è Closed.

Esempio

Nell'esempio seguente viene usato il WriteCharEntity metodo per scrivere un indirizzo di posta elettronica.

#using <System.Xml.dll>

using namespace System;
using namespace System::Xml;
int main()
{
   XmlTextWriter^ writer = nullptr;
   try
   {
      writer = gcnew XmlTextWriter( Console::Out );
      
      // Write an element.
      writer->WriteStartElement( "address" );
      
      // Write an email address using entities
      // for the @ and . characters.
      writer->WriteString( "someone" );
      writer->WriteCharEntity( '@' );
      writer->WriteString( "example" );
      writer->WriteCharEntity( '.' );
      writer->WriteString( "com" );
      writer->WriteEndElement();
   }
   finally
   {
      
      // Close the writer.
      if ( writer != nullptr )
            writer->Close();
   }

}
using System;
using System.Xml;

public class Sample {

  public static void Main() {

    XmlTextWriter writer = null;

      try {

        writer = new XmlTextWriter (Console.Out);

        // Write an element.
        writer.WriteStartElement("address");

        // Write an email address using entities
        // for the @ and . characters.
        writer.WriteString("someone");
        writer.WriteCharEntity('@');
        writer.WriteString("example");
        writer.WriteCharEntity('.');
        writer.WriteString("com");
        writer.WriteEndElement();
    }

    finally {
      // Close the writer.
      if (writer != null)
        writer.Close();
    }
  }
}
Imports System.Xml

Public Class Sample 
 
    Public Shared Sub Main() 
   
        Dim writer As XmlTextWriter = Nothing

        Try 

            writer = new XmlTextWriter(Console.Out)

            ' Write an element.
            writer.WriteStartElement("address")
     
            ' Write an email address using entities
            ' for the @ and . characters.
            writer.WriteString("someone")
            writer.WriteCharEntity("@"c)
            writer.WriteString("example")
            writer.WriteCharEntity("."c)
            writer.WriteString("com")
            writer.WriteEndElement()        
 
        Finally
            ' Close the writer.
            If writer IsNot Nothing
                writer.Close()
            End If
        End Try

    End Sub
End Class

Commenti

Nota

A partire dalla .NET Framework 2.0, è consigliabile creare XmlWriter istanze usando il metodo e la XmlWriter.Create XmlWriterSettings classe per sfruttare le nuove funzionalità.

Questo metodo scrive il carattere Unicode nel formato di riferimento dell'entità carattere esadecimale.

Si applica a