38

I need to put double quotes in configuration property Property1

 <Seection Name Propety1="" .../>
Captain Comic
  • 15,744
  • 43
  • 110
  • 148

2 Answers2

64

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

See this answer: 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.

Community
  • 1
  • 1
Andrew Barber
  • 39,603
  • 20
  • 94
  • 123
5

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
  • 16,770
  • 7
  • 43
  • 49
  • I don't understand what are you talking about. Please explain. – Captain Comic Oct 20 '10 at 15:14
  • 2
    @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 Oct 20 '10 at 15:18
  • 1
    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 Oct 20 '10 at 15:19
  • 2
    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 Oct 20 '10 at 15:27