How to prevent & to conversion and use of XmlTextWriter?

"&" in the text is escaped and converted to &when creating the xml file using XmlTextWriter but I don’t want the conversion to happen, how to prevent it?

Is there any other way besides using the WriteRaw function for xmltextwriter?

+5
source share
3 answers

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

Your two options: either output it (what your library does):

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

Or wrap it in CDATA:

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

what can be done:

xmlWriter.WriteCData("One & another");
+9
source

, ? , XML.

0

, , XmlWriterSettings, xmltextwriter.Settings, CheckCharacters.

, , , , , XML ( , xmltextwriter.

0

All Articles