XML特殊字符处理 [英] XML Special Character Handling

查看:134
本文介绍了XML特殊字符处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

VB/C#正在尝试解析包含特殊字符

VB / C# im attempting to parse the XML file which contains the special character,

replace & with &amp
' with &apos
< with &lt
> with &gt

字符串替换未替换,因为它替换了特殊字符<" ,标签中的>". 我尝试使用catch XML异常,该异常在同一行中有多个特殊字符时不起作用,如果一行中只有一个特殊字符,则可以正常工作. MS内置方法SecurityElement.Escape无效,必须在附加XML标签之前完成.

the string replace did not as it replaces the special character '<' , '>' in the the tags. i tried with catch XML exceptions that didn't work when there are multiple special characters in same line, it works if only one special character in a line. the MS builtin method SecurityElement.Escape didn't work, this has to be done before the XML tags are attached.

使用该文件加载SQL表.

im using this file to load a SQL table.

还有其他解决XML多个特殊字符的解决方案吗?

Any other solution to handle the XML multiple special characters?

推荐答案

使用System.Security.SecurityElement.Escape 例如:string XmlFriendly = System.Security.SecurityElement.Escape(坏的'string");

use System.Security.SecurityElement.Escape eg : string XmlFriendly = System.Security.SecurityElement.Escape("the bad ' string");

这篇关于XML特殊字符处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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