Leer en inglés Editar

Compartir a través de


XmlTextWriter.WriteCharEntity(Char) Method

Definition

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.

C#
public override void WriteCharEntity(char ch);

Parameters

ch
Char

Unicode character for which to generate a character entity.

Exceptions

The character is in the surrogate pair character range, 0xd800 - 0xdfff; or the text would result in a non-well formed XML document.

Examples

The following example uses the WriteCharEntity method to write an email address.

C#
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();
    }
  }
}

Remarks

Nota

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.

Applies to

Producto Versiones
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1