tags:

views:

49

answers:

2

I need to put double quotes in configuration property Property1

 <Seection Name Propety1="" .../>
+7  A: 

I believe the proper way to encode quotes in XML is via &quot;

See this answer: http://stackoverflow.com/questions/650821/how-do-i-escape-double-quotes-in-attributes-in-an-xml-string-in-t-sql

The same would go for any other 'special' characters you wish to include as data. Essentially, you should use the same encoding you would use in HTML attributes.

Andrew Barber
+3  A: 

You could html encode the value when you add it to the configuration file. This should ensure any special character will be handled correctly in the xml and be returned as expected.

Andy Rose
.net would HTML-decode the value automatically, i'd think.
cHao
I don't understand what are you talking about. Please explain.
Captain Comic
@Captain Comic: He means use `"` in the XML file, and then `System.Net.WebUtility.HtmlDecode` to decode the value in the client. But that last part should be unnecessary and even bad, as .net should already have decoded the value upon reading it from the config file.
cHao
HTML encoding is essentially the same as XML encoding, which is what my answer contained; The XML encoding for the double-quote is `"`. However, you usually do not need to de-code the information when you call the .NET configuration functions that read that information back out; Your `"` is automatically decoded back to the double-quote for you.
Andrew Barber
Just checked and Andrew Barber's and cHao's comments are correct, there is no need to decode the value when you retrieve it from the configuration file. I'll amend the answer to reflect this.
Andy Rose
+1 for good answer, and correcting the minor thing. :)
Andrew Barber