1

I'm working on some custom xml editor. I have a library that contains all the classes that can be de/serialized. The problem is that during deserialization all the comments that were in the xml are lost. Let's say I have a xml structure:

<mainNode>
    <subNode name="firstSubNode">
        <item prop1="a" prop2="b"/>
        <item prop1="c" prop2="e"/>
        <!--Here I have important comment-->
        <item prop1="d" prop2="f"/>
    </subNode>
    <!--and also here I have a comment-->
    <subNode name="secondSubNode">
        <item prop1="a" prop2="b"/>
        <item prop1="c" prop2="e"/>
    </subNode>
</mainNode>

Now when I deserialize such xml file I will have a main object (mainNode) that contains two subNodes with items. Now if I serialize this object, the result will be the same file but without comments.

The question: is there a way to keep this comments when running serialize/deserialize method? If yes how will this work when I add/remove/edit some nodes/items that contain comments.

Bartek
  • 149
  • 3
  • 13
  • 1
    possible duplicate: [http://stackoverflow.com/questions/702595/add-xml-comment-during-serialize-deserialize-with-vb-net](http://stackoverflow.com/questions/702595/add-xml-comment-during-serialize-deserialize-with-vb-net). In short, you have to serialize/deserialize objects manually in order to preserve comments. – alpha-mouse Nov 19 '10 at 09:02
  • @alpha-mouse might not be a direct duplicate but the end result is the same, I would turn your comment into an answer as it's covering the problem. – Adam Houldsworth Nov 19 '10 at 09:07
  • refer this link http://stackoverflow.com/questions/7177524/xml-serialization-collection-attribute?rq=1 – ani Nov 16 '12 at 11:19

0 Answers0