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?
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.