Main menu:


Site search

Archives

RSS Arjen's Friendfeed

RSS Richard's del.icio.us links

RSS Maurits' Stumbled Items

Archive for March, 2008

How to serialize a string as CDATA in .NET

If you want to serialize an object that contains HTML data in one of its properties, you might want to make sure the HTML ends up in a CDATA section to prevent parsing errors.

Unfortunately, you can’t just put <![CDATA[ and ]]> around your HTML string. Also, the .NET framework does not provide an attribute that tells the serializer to make a string into a CDATA section.

However, you can declare a property of the type XMLCDataSection to get the desired result.