XmlTextWriter::WriteCharEntity Method (Char)
.NET Framework (current version)
Forces the generation of a character entity for the specified Unicode character value.
Assembly: System.Xml (in System.Xml.dll)
Parameters
- ch
-
Type:
System::Char
Unicode character for which to generate a character entity.
| Exception | Condition |
|---|---|
| ArgumentException | The character is in the surrogate pair character range, 0xd800 - 0xdfff; or the text would result in a non-well formed XML document. |
| InvalidOperationException | The WriteState is Closed. |
Note |
|---|
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. |
This method writes the Unicode character in hexadecimal character entity reference format.
The following example uses the WriteCharEntity method to write an e-mail 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 e-mail 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(); } }
.NET Framework
Available since 1.1
Available since 1.1
Show:
