Created
April 6, 2010 19:21
-
-
Save mbriggs/357976 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static string EscapeXml( this string s ) | |
{ | |
string xml = s; | |
if ( !string.IsNullOrEmpty( xml ) ) | |
{ | |
// replace literal values with entities | |
xml = xml.Replace( "&", "&" ); | |
xml = xml.Replace( "<", "<" ); | |
xml = xml.Replace( ">", ">" ); | |
xml = xml.Replace( "\"", """ ); | |
xml = xml.Replace( "'", "'" ); | |
} | |
return xml; | |
} | |
public static string UnescapeXml( this string s ) | |
{ | |
string unxml = s; | |
if ( !string.IsNullOrEmpty( unxml ) ) | |
{ | |
// replace entities with literal values | |
unxml = unxml.Replace( "'", "'" ); | |
unxml = unxml.Replace( """, "\"" ); | |
unxml = unxml.Replace( ">", ">" ); | |
unxml = unxml.Replace( "<", "<" ); | |
unxml = unxml.Replace( "&", "&" ); | |
} | |
return unxml; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment