Friday, November 02, 2012

C# : & in the XML

 

If you have an XML string (e.g. the appSettings in web.config) that contains an “&” it won’t compile e.g.

<add key="URL" value="http://example.com?ID1=abc&ID2=123"/>

The solution is to escape it with the Unicode number i.e.

<add key="URL" value="http://example.com?ID1=abc&#038;ID2=123"/>

Enjoy!

No comments: