Ask Learn
Preview
Please sign in to use this experience.
Sign inThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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)
Unicode character for which to generate a character entity.
The character is in the surrogate pair character range, 0xd800
- 0xdfff
; or the text would result in a non-well formed XML document.
The WriteState is Closed
.
The following example uses the WriteCharEntity
method to write an email address.
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
Note
We recommend that you create XmlWriter instances by using the XmlWriter.Create method and the XmlWriterSettings class to take advantage of new functionality.
This method writes the Unicode character in hexadecimal character entity reference format.
.NET feedback
.NET is an open source project. Select a link to provide feedback:
Please sign in to use this experience.
Sign in