XML Utility Method in .NET BCL

XML has a set of special characters that cannot appear in element/attribute names and values: &, <, >, ” and ‘. For example, <entityText>Mark & Spencer’s</entityText> is not valid. The valid equivalent is <companyName>Mark &amp; Spencer&apos;s</companyName>. Here is the list of XML special characters and their entity names:

&

&amp;

>

&gt;

<

&lt;

&quot;

&apos;

 

There is a nice utility method in .NET which does this conversion when working with such XML: System.Security.SecurityElement.Escape().