Type Reason InvalidOperationException The XmlTextWriter.WriteState is WriteState.Closed and text is neither null nor string.Empty.
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 &, <, and >, respectively.
Character values in the range 0x-0x1F (excluding white space characters 0x9, 0xA, and 0xD) are replaced with numeric character entities (� through �x1F).
If WriteString is called in the context of an attribute value, double and single quotes are replaced with " and ' respectively.
For example, this input string test<item>test is written as
Example
test<item>test
If text is either null or String.Empty, this method writes a text node with no data content.
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
<1 & 2 = 3>