Tags with nilllable and minoccures=0 getting lost in deserialize/serialize
Hi all!
I have run into some strange behaviour in XmlSerializer. (.net 2.0)
1. I have a normal (but quite large) XSD-schema and an XML-file that is
valid.
2. I use xsd.exe to generate classes.
3. I deserialize the xml-file with XmlSerializer.deserialze() to an
object ( instance from the generated classes)
4. I serialize the object back to xml.
5. Now I have lost all the xml-elements that was marked nillable and
minoccurs=0 in the schema. Even if they were present in the original
xml-file.
6. I expected that a deserialize followed by a serialize wouldn't
loose information.
Some further analysis:
The classes generated by xsd.exe has the property fieldnameSpecified
for all fields with minoccurs=0.
During serialize, the serializer checks if fieldnameSpecified is true,
otherwise the field is not serialized.
During deserilize fieldnameSpecified is ALWAYS set to False if the
field is nillable and minoccurs=0 and as a result of this, WILL NOT be
serialized later on.
Any one out there with any information about this strange behaviour?
Is it normal?
Some workarounds?
Am I missing some important info?
Have a nice weekend!
Regards
/Stefan Vestin
|