System.Xml.XmlTextWriter.WriteString Method

Writes the given text content.

Syntax

public override void WriteString (string text)

Parameters

text
Text to write.

Exceptions

TypeReason
InvalidOperationExceptionThe XmlTextWriter.WriteState is WriteState.Closed and text is neither null nor string.Empty.

Remarks

Note:

In the dnprdnext release, the recommended practice is to create System.Xml.XmlWriter instances using the erload:System.Xml.XmlWriter.Create method and the System.Xml.XmlWriterSettings class. This allows you to take full advantage of all the new features introduced in this release. For more information, see Creating XML Writers.

WriteString does the following

  • The characters &, <, and > are replaced with &amp;, &lt;, and &gt;, respectively.

  • Character values in the range 0x-0x1F (excluding white space characters 0x9, 0xA, and 0xD) are replaced with numeric character entities (&#0; through &#0x1F).

  • If WriteString is called in the context of an attribute value, double and single quotes are replaced with &quot; and &apos; respectively.

For example, this input string test<item>test is written as

Example

 test&lt;item&gt;test

If text is either null or String.Empty, this method writes a text node with no data content.

Example

The following example demonstrates the conversions performed by this method.

C# Example

using System;
using System.Xml;

public class WriteFrag {

  public static void Main() {

    XmlTextWriter xtWriter =
      new XmlTextWriter(Console.Out);
    xtWriter.WriteString("<1 & 2 = 3>");
  }
}
   

The output is

&lt;1 &amp; 2 = 3&gt;

Requirements

Namespace: System.Xml
Assembly: System.Xml (in System.Xml.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0