XmlTextWriter.WriteCharEntity(Char) XmlTextWriter.WriteCharEntity(Char) XmlTextWriter.WriteCharEntity(Char) XmlTextWriter.WriteCharEntity(Char) Method

Definizione

Forza la generazione di un'entità carattere per il valore del carattere Unicode specificato.Forces the generation of a character entity for the specified Unicode character value.

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 Char Char Char

Carattere Unicode per il quale generare l'entità di caratteri.Unicode character for which to generate a character entity.

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.The character is in the surrogate pair character range, 0xd800 - 0xdfff; or the text would result in a non-well formed XML document.

Esempi

Nell'esempio seguente viene usato WriteCharEntity il metodo per scrivere un indirizzo di posta elettronica.The following example uses the WriteCharEntity method to write an email address.

#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 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.

Questo metodo scrive il carattere Unicode nel formato di riferimento a entità carattere esadecimale.This method writes the Unicode character in hexadecimal character entity reference format.

Si applica a