문제

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?

도움이 되었습니까?

해결책

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");

다른 팁

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

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top