0

Is there a .NET (2.0) framework method to remove the XML special characters?

Like " & etc.

It's easy enough to write one, but I'd rather use the framework's if one is available.

Adam Neal
  • 2,147
  • 7
  • 24
  • 39
  • possible duplicate of http://stackoverflow.com/questions/1132494/string-escape-into-xml –  May 07 '10 at 13:59
  • My preferred answer: http://stackoverflow.com/questions/1132494/string-escape-into-xml/1132679#1132679 –  May 07 '10 at 13:59

2 Answers2

1

Assuming you mean you want to escape the characters, i.e. & becomes & then I don't think there is a framework method for that, closest is probably the HTMLEncode and HTMLDecode on the HTTPServerUtility class. Could always wrap your data in CDATA tags to avoid parsing of those characters.

Lazarus
  • 41,906
  • 4
  • 43
  • 54
0

I suggest taking a look at the XMLConvert class. You can use it to encode and Decode XML to make it safe. This will also handle illegal characters as defined in the XML Spec. Removing characters changes the underlying data and it is better to encode and decode them.

SoftArtisans
  • 536
  • 3
  • 5