避免逃避 '具有 .NET XmlDocument 类的实体 [英] Avoid escaping ' entity with .NET XmlDocument class

查看:28
本文介绍了避免逃避 '具有 .NET XmlDocument 类的实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何避免 XmlDocument 类替换 '带有 ' 字符的实体?例如,如果我有:

How can I avoid XmlDocument class replace ' entity with the ' character? For example if I have:

string xml = "<a> &apos; </a>";

做完之后

var doc = new XmlDocument();
doc.LoadXml(xml);
string output = doc.OutterXml;

输出的值为

"<a>'</a>"

我需要避免这种情况,因为我必须加载 XML,进行一些更改并对其进行数字签名,因此签名的 XML 必须与加载的相同.

I need to avoid this because I must load an XML, make some changes and sign it digitally so the signed XML must be the same loaded.

推荐答案

对于您的特定要求,请勿使用 XmlDocument 或任何其他 XML 解析器来解析原始文档.

For your specific requirements, don't use XmlDocument or any other XML parser to parse the original document.

务必使用 XmlDocument 或任何其他特定于 XML 的类来创建新文档,除非在原始文档需要放置的地方放置一个占位符,例如 ORIGINAL_DOCUMENT_HERE.然后,在为新文档生成结果文本 XML 后,将 ORIGINAL_DOCUMENT_HERE 替换为您收到的原始文本,然后对结果进行签名.

Do use XmlDocument or any other XML-specific classes to create your new document, except put a placeholder where the original document needs to go, like ORIGINAL_DOCUMENT_HERE. Then after you've generated the resulting text XML for your new document, replace ORIGINAL_DOCUMENT_HERE with your original received text, and then sign the result.

不是处理 XML 的正常方式,但应该适用于您的特定用例.

Not a normal way to work with XML, but should work for your specific use case.

这篇关于避免逃避 &amp;apos;具有 .NET XmlDocument 类的实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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