I have the following function:
Private Function XMLEncode(ByVal s As String) As String
Return s.Replace("&", "&").Replace("<", "<").Replace(">", ">").Replace("'", "'").Replace("""", """).Replace("AMP",amp)
End Function
but the above takes the string "TYNE & WEAR" and produces:
TYNE &amp; WEAR
I just want it to be TYNE & WEAR
The xml is built with StringBuilder and that is what I am stuck with right now. I know .net takes care of this for you.
Update:
Instead of having this function yourself (and reinventing the wheel), you can use SecurityElement.Escape:
or HttpUtility.HtmlEncode (if you’re in ASP.Net)
Also, instead of
StringBuilder, if you can switch toXmlTextWriter, thenXmlTextWriter.WriteString()will do the escaping for you.