Share via


How to escape XML string characters?

Question

Thursday, January 28, 2010 4:11 PM

Hi,

For example I need to convert string "Mark's Marine Inc" to "Mark's Marine Inc".

But instead that resultXML  contains "Mark's Marine Inc".

What is wrong with my code? Unfortunately I can use just .NET 3.0

XmlElement xmlField = xmlDoc.CreateElement("Keyword"); 

xmlField.SetAttribute("Name", idxControl.Column.Name); 

xmlField.InnerText = idxControl.Value.Replace("&", "&").Replace("<", "<").Replace(">", ">").Replace("\", """).Replace("'", "'"); xmlKeywords.AppendChild(xmlField); 

 ... 

resultXml = xmlDoc.OuterXml;

Oleg

All replies (1)

Thursday, January 28, 2010 10:31 PM âś…Answered | 2 votes

This link provides several options for escaping XML characters with C#:

http://weblogs.sqlteam.com/mladenp/archive/2008/10/21/Different-ways-how-to-escape-an-XML-string-in-C.aspx

Hope this helps.www.insteptech.com ; msmvps.com/blogs/deborahk
We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!