views:

214

answers:

3

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?

+2  A: 

Why don't you want this to happen ? It looks to me like the library is enforcing correct character escaping as required by XML.

Brian Agnew
some people just need it. dont answer a question with another question. tell him how, or say nothing at all.
Chris
Lol @Chris. Sometimes you learn a lot more when your question is answered with a question, unless you are lazy...
Rob Fonseca-Ensor
@Rob Maybe, but a question is still not an *answer*, and is just getting in the way of the actual answers (especially as for some reason its being up-voted) - this should have been a comment.
Kragen
@Chris: A counter-question is *of course* an answer. It makes the other one *think*. Most if not all questions that are replied to with another question are either not well thought-out (95%) or not clearly formulated (5%). Making questioners *think* leads to greater understanding for them, since an answer that you find yourself weighs more than one that your have been just told. Besides, not questioning motives is a foolish mindset for a programmer.
Tomalak
@Tomalak - thanks for that. That was a more lucid comment than the one I was just formulating.
Brian Agnew
Counter questions are necessary i suppose as it enables us to interact thereby creating a discussion :P
Well i just wanted to output the data in xml format, i know it would throw an error if u dont escape it
@kragen when you say "not an answer", do you mean "not an answer in the stackoverflow sense"?I agree that *maybe* this would have been more appropriate as a comment on the question.
Rob Fonseca-Ensor
+6  A: 

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");
Paolo
lavinio
You are right, i just want it in a xml format thats all, i am not going to read it
A: 

I am not sure if it will work, but you might want to check into the XmlWriterSettings Properties available through xmltextwriter.Settings, especially the CheckCharacters property.

On the other hand, as Brian Agnew mentioned, not encoding the & to & might be the wrong way to go as it will invalidate your XML (unless you already encoded it to & in which case you might just want to decode it before giving it to the xmltextwriter class.

dbemerlin