在我的应用程序中,我使用XAttribute.SetValue(...)来设置xml属性的值。该值由用户提供。
我有以下方法来设置属性值:
private void SetValue(XAttribute attribute, string input)
{
attribute.SetValue(input);
}如果输入为Hello "World",则属性值为:Hello "World"
这正是我所期望的。
如果输入已经像Hello "World"一样被“屏蔽”了,那么属性值是:Hello "World"
这是不正确的。
有没有办法避免这种转换?
发布于 2019-08-19 23:15:54
您不能停止将字符(如& )编码为实体代码的SetValue。因此,为了避免对它们进行双重编码,您可以确保您的输入一开始就没有编码。您可以使用以下命令执行此操作:
System.Net.WebUtility.HtmlDocode(input)
或者,如果您已经有对System.Web的引用,
System.Web.HttpUtility.HtmlDecode(input)
https://stackoverflow.com/questions/57554250
复制相似问题