Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

The '&' in the text gets escaped and gets converted to & 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?

like image 345
kurozakura Avatar asked Feb 01 '10 13:02

kurozakura


People also ask

How do you prevent implicit conversions in C++?

Keyword explicit tells compiler to not use the constructor for implicit conversion. For example declaring Bar's constructor explicit as - explicit Bar(int i); - would prevent us from calling ProcessBar as - ProcessBar(10); .

What are the two types of conversions?

There are two types of conversion: implicit and explicit.


1 Answers

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");
like image 124
Paolo Avatar answered Sep 26 '22 14:09

Paolo