Monday, March 31, 2008

This Blog Has Moved!

This is friendly reminder that if you're looking for new and fresh content from yours truly (Caveman), you should head on over to my new blog at Caveman's blog

Tuesday, March 25, 2008

Replace special characters in XML, using C#

We can use the SecurityElement.Escape method to replace the invalid XML characters in a string with their valid XML equivalent [1].

Namespace: System.Security
Assembly: mscorlib (in mscorlib.dll)

I have used the HttpUtility classes UrlEncode and UrlDecode methods to handle cross-site scripting attacks and this also helped me to get rid of the XmlException - "Data at the root level is invalid".

Reference:
1. MSDN