.Net 是否有 org.apache.commons.lang.StringEscapeUtils 的实现?
我正在移植我编写的一个 Java 项目,该项目使用 Apache Commons Lang StringEscapeUtils 类(特别是
escapeXml
unescapeXml
escapeHtml
unescapeHtml
方法)。有 .Net 等效项吗?或者也许是一些完全符合逻辑的 C# 代码可以完成同样的事情?
I'm porting over a Java project that I wrote which uses the Apache Commons Lang StringEscapeUtils class (particularly the
escapeXml
unescapeXml
escapeHtml
unescapeHtml
methods). Is there a .Net equivalent? Or perhaps some totally logical bit of C# code that accomplishes the same thing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用 System.Web for HTML 有:
对于XML 转义可以使用 SecurityElement.Escape 方法 在 System.Security 命名空间中。然而,据我所知,没有等同于 unescape it 的方法。您必须编写自己的方法来替换编码的 XML,例如
<
和&
等及其等效项。转义方法的链接列出了其他项目。Using System.Web for HTML there is:
For XML escaping you can use the SecurityElement.Escape method in the System.Security namespace. However, there's no equivalent to unescape it that I am aware of. You would have to write your own method that replaces the encoded XML, such as
<
and&
etc. with their equivalents. The link for the escape method lists the other items.您可以使用 HtmlEncode 和 HtmlDecode 用于 Html 替换。您可以找到 XML 转义选项 此处。
You could use the HtmlEncode and HtmlDecode for the Html replacements. Your options for XML escaping can be found here.
查看 HttpServerUtility 类
HttpServerUtility.HtmlEncode、HtmlDecode、UrlDecode 等...
也适用于 XML:
System.Xml.XmlConvert
System.Security.SecurityElement。逃脱
Check out HttpServerUtility Class
HttpServerUtility.HtmlEncode, HtmlDecode, UrlDecode etc etc...
Also for XML:
System.Xml.XmlConvert
System.Security.SecurityElement.Escape