Mono Class Library: System.Xml.XmlTextWriter Overview | Members

System.Xml.XmlTextWriter.WriteString Method

Writes the specified text.

public override void WriteString (string text)

Parameters

text
A string specifying the text to write.

Exceptions

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

Remarks

This method performs the following conversions before writing the text:

  • The characters '&', '<', and '>' are replaced with "&amp;", "&lt;", and "&gt;", respectively.
  • Character values in the range 0x-0x1F (excluding the white space characters 0x9, 0x10, and 0x13) are replaced with numeric character entities ("&#0;" through "&#0x1F").
  • If called in the context of an attribute value, double and single quotes are replaced with "&quot;" and "&apos;" respectively.

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

Note:

This method overrides XmlWriter.WriteString(string).

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