问题描述
当使用XmlTextWriter
创建xml文件时,文本中的'&'转义并转换为& amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp;转换发生如何防止它?
The '&' in the text gets escaped and gets converted to
&
when creating the xml file using XmlTextWriterbut i dont want the conversion to take place how to prevent it?
除了使用xmltextwriter的WriteRaw func还有其他方法?
Is there any other way besides using WriteRaw func of xmltextwriter?
推荐答案
如果你将一个未转义的&符号放在XML中,它就不再是有效的XML。
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 & another</tag>
或将其包装在CDATA中:
Or wrap it in CDATA:
<tag><![CDATA[One & another]]></tag>
可以通过以下方式完成:
which can be done by:
xmlWriter.WriteCData("One & another");
这篇关于如何防止&到& amp;使用XmlTextWriter?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!