Teilen über


XmlTextWriter.WriteCharEntity(Char) Methode

Definition

Erzwingt das Generieren einer Zeichenentität für den angegebenen Unicode-Zeichenwert.

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

Parameter

ch
Char

Unicode-Zeichen, für das eine Zeichenentität generiert werden soll.

Ausnahmen

Das Zeichen liegt im Ersatzzeichenpaar-Bereich, 0xd800 - 0xdfff, oder aus dem Text würde ein wohlgeformtes XML-Dokument resultieren.

Beispiele

Im folgenden Beispiel wird die WriteCharEntity Methode verwendet, um eine E-Mail-Adresse zu schreiben.

#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

Hinweise

Hinweis

Ab dem .NET Framework 2.0 empfehlen wir, Instanzen mithilfe der Methode und der XmlWriter.Create XmlWriterSettings Klasse zu erstellenXmlWriter, um neue Funktionen zu nutzen.

Diese Methode schreibt das Unicode-Zeichen im Hexadezimalzeichen-Entitätsreferenzformat.

Gilt für