Skip to content

Instantly share code, notes, and snippets.

@Microsofttechies
Created April 14, 2015 07:55
Show Gist options
  • Select an option

  • Save Microsofttechies/ccf5f9c4b5db5d4a3f11 to your computer and use it in GitHub Desktop.

Select an option

Save Microsofttechies/ccf5f9c4b5db5d4a3f11 to your computer and use it in GitHub Desktop.
Read special characters back from XmlDocument in c#
To Get escapded values
public string EscapeXMLValue(string value)
{
if (string.IsNullOrEmpty(s)) return s;
string temp = s;
temp = temp.Replace("'","&apos;").Replace( "\"", "&quot;").Replace(">","&gt;").Replace( "<","&lt;").Replace( "&","&amp;");
return temp ;
}
To get the unescaped value
public string UnescapeXMLValue(string xmlValue)
{
if (string.IsNullOrEmpty(s)) return s;
string temp = s;
temp = temp.Replace("&apos;", "'").Replace("&quot;", "\"").Replace("&gt;", ">").Replace("&lt;", "<").Replace("&amp;", "&");
return temp ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment