I have an XML document that I am deserializing (VB .NET 3.5 Framework), changing some values, and the serializing again. The original document has several XML Comments in it. When I go through all the deserialize/serialize all of the comments are lost. Is there a way to preserve the comments? If not, is there a way to add comments on serialization without having to walk through with the writer and manually add all of the comments back in the appropriate place?
+2
A:
No, there isn't. If you want to serialize the contents then you will have to use custom serialization (I assume you are referring to implementing IXmlSerializable) and store the comments in the instance of the class and reserialize them when serializing back to XML.
The runtime can't possibly know that the comment is supposed to be serialized and store it for you, so you have to do it yourself.
casperOne
2009-03-31 19:28:55