Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old March 10th, 2006, 10:05 AM
svestin@bigfoot.com
Guest
 
Posts: n/a
Default 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

 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles