如何防止&到& amp;使用XmlTextWriter? [英] How to Prevent the conversion of & to & using XmlTextWriter?

查看:184
本文介绍了如何防止&到& amp;使用XmlTextWriter?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用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 XmlTextWriter but 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 &amp; another</tag>

或将其包装在CDATA中:

Or wrap it in CDATA:

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

可以通过以下方式完成:

which can be done by:

xmlWriter.WriteCData("One & another");

这篇关于如何防止&amp;到&amp; amp;使用XmlTextWriter?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆