How to Prevent the conversion of & to & using XmlTextWriter?

c#, escaping, vb.net, xml, xmltextwriter

Solution

If you put an unescaped ampersand in XML it is no longer valid XML.

Your two choices are either escape it (which your library is doing):

<tag>One &amp; another</tag>

Or wrap it in CDATA:

<tag><![CDATA[One & another]]></tag>

which can be done by:

xmlWriter.WriteCData("One & another");

Problem

The '&' in the text gets escaped and gets converted to `&amp;` when creating the xml file using XmlTextWriter but i dont want the conversion to take place how to prevent it? Is there any other way besides using WriteRaw func of xmltextwriter?

Original source