I've a requirement to serialize any class provided (decorated with the appropriate XmlElement/ XmlAttribute etc), but some of the properties may contain some sort of mark-up...usually HTML, but it could as easily be XML in the future.
When trying to serialize the class the XmlSerializer crashes.
I'd hope to be able to apply no more than an attribute to the property (currently set to XmlText) in the hope that it would wrap the content in CDATA[...]
, but that doesn't seem to work.
I've seen several 'workarounds' like the one here, but I'd hoped for something a little less impactful for the developing consumer.
Does anyone know of any 'nicer' less invasive solution...?
Thanks, Kieron
Edit:
Based on Damian's answer, I found thi开发者_运维技巧s article which shows the differences between the XmlSerializer and the DataContractSerializer - http://www.danrigsby.com/blog/index.php/2008/03/07/xmlserializer-vs-datacontractserializer-serialization-in-wcf/
Just a thought, but does the DataContractSerializer have the same problem?
精彩评论