I came across this method SecurityElement.Escape(string)to avoid special XML characters in String, however it seems to fit weirdly into the Security namespace given that I just use a common System.Xml namespace and a non-security XML base string.
It converts the following special XML characters.
< to <
> to >
" to "
' to '
& to &
Is there an equally fast call to a static method somewhere inside the XML namespace to escape these characters without using higher-level classes such as XmlReader, XmlDocument, etc.?
source
share