gov.va.medora.mdws.MdwsUtils.replaceSpecialXmlChars C# (CSharp) Method

replaceSpecialXmlChars() public static method

Replaces special characters in strings.
* Behaves like XmlTextWriter.WriteString(), but also replaces the apostrophe and double-quote characters -- which WriteString() does not, unless it is in an attribute context... * PERFORMANCE NOTE: About 2.5 s slower than old method over the course of 1 million runs. TBD see if there is a good way for us to reuse the StringWriter and XmlTextWriter so that we don't have to keep recreating them. Maybe a factory method?
public static replaceSpecialXmlChars ( string s ) : string
s string
return string
        public static string replaceSpecialXmlChars(string s)
        {
            // this takes care of all of the characters except ' and " because
            // we are not processing within the context of an attribute
            //
            System.IO.StringWriter stringWriter = new System.IO.StringWriter();
            using (XmlWriter writer = new XmlTextWriter(stringWriter))
            {
                writer.WriteString(s);
                stringWriter.Close();
                writer.Close();
            }
            string result = stringWriter.ToString();
            result = result.Replace("\"", """);
            result = result.Replace("'", "'");
            return result;
        }