停止逃避" [英] Stop unescaping "

查看:29
本文介绍了停止逃避"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在读取 XML 文件并向其添加节点时遇到问题.不完全是.. 添加节点工作正常,但源 XML 文件包含一些包含 "

I'm having trouble reading an XML file and adding nodes to it. Well not exactly.. adding nodes works fine, but the source XML File contains some Lines containing "

在保存我的 xmlDocument 之后,那些 " 部分被转换为 "

After Saving my xmlDocument those " parts are converted to "

如何防止 c# 将 " 转换为 " 因为加载 xml 文件的应用程序需要那些 "> 标记

How can i prevent c# from converting " to " because the application that loads the xml file needs those " marks

示例行:

DBName "xyz"

推荐答案

你不需要在元素中编码引号,只需要在属性中编码.所以:

You don't need to encode quotation marks in elements, only in attributes. So:

<item name="Description">DBName &quot;xyz&quot;</item>

是不必要的,你可以使用:

is unnecessary, you can just use:

<item name="Description">DBName "xyz"</item>

当您在元素中不必要地放置编码引号 (&quot;) 并且默认情况下 XmDocument.Save() 将它们替换为未编码的引号 (") 时,似乎 XmlDocument.Load() 理解您的意思.

It seems XmlDocument.Load() understands what you mean when you unnecessarily put encoded quotations marks (&quot;) in an element and that by default XmDocument.Save() replaces them with unencoded quotation marks (").

如果您的来源是:

<item name="Description">DBName &#34;xyz&#34;</item>

其中 " 是 "

https://stackoverflow.com/a/150441/283787 说明:" 不是字符必须在元素数据中编码.

如果你想预设空格,只需添加以下代码行:

If you want to presetve whitespace, simple add the following line of code:

doc.PreserveWhitespace = true;

这篇关于停止逃避&amp;quot;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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