XmlTextWriter.WriteCharEntity(Char) Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Force la génération d’une entité de caractère pour la valeur de caractère Unicode spécifiée.
public:
override void WriteCharEntity(char ch);
public override void WriteCharEntity(char ch);
override this.WriteCharEntity : char -> unit
Public Overrides Sub WriteCharEntity (ch As Char)
Paramètres
- ch
- Char
Caractère Unicode pour lequel générer une entité de caractère.
Exceptions
Le caractère se trouve dans la plage de caractères de paire de substitution ; 0xd800 - 0xdfffou le texte entraînerait un document XML non bien formé.
WriteState a la valeur Closed.
Exemples
L’exemple suivant utilise la WriteCharEntity méthode pour écrire une adresse e-mail.
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
Remarques
Note
Nous vous recommandons de créer XmlWriter instances en utilisant la méthode XmlWriter.Create et la classe XmlWriterSettings pour tirer parti de nouvelles fonctionnalités.
Cette méthode écrit le caractère Unicode au format de référence d’entité hexadécimale.